﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml;
using NursingFormSystem;

namespace NursingFormSystem
{
    /// <summary>
    /// 体温单绘制对象
    /// </summary>
    [System.Runtime.InteropServices.ComVisible(false)]
    public class TemperatureDocumentRender
    {

        /// <summary>
        /// 初始化对象
        /// </summary>
        public TemperatureDocumentRender(int _printType)
        {

        }

        int printType = 0;//0-正常显示 1-打印 针对打印需做一些特别处理
        float MemoIn = 0f;//定义上事件起绘点
        float MemoUp = 0f;//定义下事件起绘点       
        /// <summary>
        /// 绘制体温单
        /// </summary>
        /// <param name="g">画布对象</param>
        public void Draw(Graphics g, TemperatureDocument document, int _printType)
        {
            if (document == null)
            {
                return;
            }
            printType = _printType;
            TemperatureDocumentOptions options = document.Options;

            //HeaderLines页眉信息栏
            foreach (TitleLineInfo line in options.HeaderLines)
            {
                line.RuntimeStartDate = line.StartDate;
                if (line.ValueType == TitleLineValueType.DayIndex || line.ValueType == TitleLineValueType.ChildBirthDay)
                {
                    if (line.RuntimeStartDate == TemperatureDocument.NullDate)
                    {
                        if (string.IsNullOrEmpty(line.StartDateKeyword) == false)
                        {
                            line.InRuntimeStartDate = new List<DateTime>();
                            foreach (Measure m in document.Measures)
                            {
                                //当Showtype为1表示新生儿手术后日数变成出生日数根据出生事件自动增长
                                //if (document.ShowType=="1" )
                                //{
                                //    if (m.MemoIn != null
                                //  && m.MemoIn.IndexOf("出生") >= 0 && line.Text.Contains("分娩")==false)
                                //    {
                                //        line.InRuntimeStartDate.Add(m.ValueDate);//添加符合条件的元素
                                //    }
                                //}
                                if (line.StartDateKeyword.Contains("/"))
                                {
                                    string[] lineKeywordS = line.StartDateKeyword.Split('/');
                                    for (int i = 0; i < lineKeywordS.Length; i++)
                                    {
                                         if (m.MemoIn != null
                                   && m.MemoIn.IndexOf(lineKeywordS[i]) >= 0)
                                    {
                                        //line.RuntimeStartDate = m.ValueDate;
                                        //break;
                                        line.InRuntimeStartDate.Add(m.ValueDate);//添加符合条件的元素
                                    }
                                    }
                                }
                                else
                                {
                                    if (m.MemoIn != null
                                   && m.MemoIn.IndexOf(line.StartDateKeyword) >= 0)
                                    {
                                        //line.RuntimeStartDate = m.ValueDate;
                                        //break;
                                        line.InRuntimeStartDate.Add(m.ValueDate);//添加符合条件的元素
                                    }
                                }                             
                            }
                        }
                    }
                }
                else if (line.ValueType == TitleLineValueType.InDayIndex)
                {
                    if (line.RuntimeStartDate == TemperatureDocument.NullDate)//入院日期为空则取第一条记录为入院日期
                    {
                        if (Convert.ToDateTime(document.InDate) != TemperatureDocument.NullDate)
                        {
                            line.RuntimeStartDate = Convert.ToDateTime(Convert.ToDateTime(document.InDate).ToShortDateString());
                        }
                        else
                        {
                            if (document.Measures.Count > 0)
                            {
                                line.RuntimeStartDate = document.Measures[0].ValueDate;
                            }
                        }
                    }

                }
            }

            Font labelFont = null;
            if (string.IsNullOrEmpty(options.FontName))
            {
                labelFont = new Font(
                    System.Windows.Forms.Control.DefaultFont.Name,
                    options.FontSize);
            }
            else
            {
                labelFont = new Font(
                    options.FontName,
                    options.FontSize);
            }
            StringFormat centerFormat = new StringFormat();
            centerFormat.Alignment = StringAlignment.Center;
            centerFormat.LineAlignment = StringAlignment.Center;
            centerFormat.FormatFlags = System.Drawing.StringFormatFlags.FitBlackBox
                    | System.Drawing.StringFormatFlags.MeasureTrailingSpaces
                    | StringFormatFlags.NoClip | StringFormatFlags.NoWrap;

            StringFormat leftFormat = new StringFormat();
            leftFormat.Alignment = StringAlignment.Near;
            leftFormat.LineAlignment = StringAlignment.Center;
            leftFormat.FormatFlags = System.Drawing.StringFormatFlags.FitBlackBox
                    | System.Drawing.StringFormatFlags.MeasureTrailingSpaces
                    | StringFormatFlags.NoClip | StringFormatFlags.NoWrap;
            if (options.BackColor.A != 0)
            {
                // 绘制背景
                using (SolidBrush b = new SolidBrush(options.BackColor))
                {
                    g.FillRectangle(
                        b,
                        options.Left,
                        options.Top,
                        options.Width,
                        options.Height);
                }
            }

            // 计算Y坐标轴文本占据的宽度
            float totalYAxisWidth = 0;
            foreach (YAxisInfo info in options.YAxisInfos)
            {
                if (info.Types != 2)
                {
                    string title = info.Title;
                    string titleUnit = info.Unit;
                    int types = info.Types;
                    if (string.IsNullOrEmpty(title))
                    {
                        title = "HHHH";
                    }
                    // 根据单位以及名称，获取最大长度，设为宽度
                    SizeF size = g.MeasureString((title.Length > titleUnit.Length ? title : titleUnit), labelFont);
                    info.ViewLeft = totalYAxisWidth;
                    //此处单独设置疼痛评分宽度
                    if (types == 1)
                    {
                        info.ViewWidth = labelFont.GetHeight(g);
                    }
                    else
                    {
                        info.ViewWidth = size.Width * 1.1f;
                    }
                    //心率列宽度不计算
                    if (info.ValueMember != ValueMemberType.HeartRate)
                    {
                        totalYAxisWidth += info.ViewWidth;
                    }
                }
            }

            // 根据标题行文本的宽度设置左边缘区域宽度
            List<string> titleTexts = new List<string>();
            int trueIndex = 0;  //实际需要绘制的行数
            foreach (TitleLineInfo info in options.HeaderLines)
            {
                if (info.ShowType == "" || info.ShowType.Contains(document.ShowType))
                { titleTexts.Add(info.Text); trueIndex++; }
            }
            foreach (TitleLineInfo info in options.FooterLines)
            {
                if (info.Text.Contains("体重/身高"))
                {
                    info.Text = "体重(Kg)/身高(cm)";
                }
                titleTexts.Add(info.Text);
            }
            foreach (string text in titleTexts)
            {
                if (string.IsNullOrEmpty(text))
                {
                    continue;
                }
                SizeF size = g.MeasureString(text, labelFont);
                totalYAxisWidth = Math.Max(totalYAxisWidth, size.Width);
            }//foreach

            //float RightYAxisWidth = 25f;//定义右边栏目宽度

            // 有数据的时间区间的最大值
            DateTime maxDate = TemperatureDocument.NullDate;
            // 有数据的时间区间的最小值
            DateTime minDate = TemperatureDocument.NullDate;
            document.UpdateNumOfPage(out maxDate, out minDate);

            // 当前区域的开始时间
            DateTime startDate = minDate.AddDays(
                document.PageIndex * options.NumOfDaysInOnePage);

            // 计算标题行高度
            float titleLineHeight = labelFont.GetHeight(g) * 1.5f;
            // 标题行总高度
            float totalHeaderLineHeight = titleLineHeight * trueIndex;

            // 标题栏高度
            float titleHeight = 0;

            titleHeight = titleLineHeight * 3; //titleLineHeight * 3;
            float titleHeight2 = titleLineHeight * 2 + 9; //titleLineHeight * 3;
            // 绘制大标题
            XmlNodeList HospitalNodeList = document.Options.configXml.SelectNodes("TemperatureDocument/Hospital");
            float HospitalTop = options.Top;
            foreach (XmlNode HospitalNode in HospitalNodeList)
            {
                using (Font titleFont = new Font(
           labelFont.Name,
           labelFont.Size * Convert.ToSingle(2.5),
           labelFont.Style))
                {
                    RectangleF titleTextBounds = new RectangleF(
                        options.Left,
                        HospitalTop - 10,
                        options.Width,
                        titleHeight / HospitalNodeList.Count);
                    g.DrawString(
                        string.IsNullOrEmpty(HospitalNode.Attributes["Name"].Value) ? "体温单" : HospitalNode.Attributes["Name"].Value,
                        titleFont,
                        //Brushes.Black,
                        new SolidBrush(ColorTranslator.FromHtml(HospitalNode.Attributes["Color"].Value)),
                        titleTextBounds,
                        centerFormat);
                }
                HospitalTop += titleHeight / HospitalNodeList.Count;
            }

            //患者信息栏数据加载
            List<string> infoTitle = new List<string>();
            XmlNodeList TitlesNodeList = document.Options.configXml.SelectNodes("TemperatureDocument/Titles/Title");
            
            //获取转科转床数据
            string[] result = UpdateTransferBedOrDept(document);
            foreach (XmlNode TitlesNode in TitlesNodeList)
            {
                var na = document.GetType().GetProperty(TitlesNode.Attributes["Id"].Value);

                if (na != null)
                {
                    string text = TitlesNode.Attributes["Name"].Value + ":" + na.GetValue(document, null);
                    if (TitlesNode.Attributes["Name"].Value == "科室" || TitlesNode.Attributes["Name"].Value == "科室")
                    {
                        if(result[1] != "") text = TitlesNode.Attributes["Name"].Value + ":" + result[1];
                    }
                    else if (TitlesNode.Attributes["Name"].Value == "床号")
                    {
                        if(result[0] != "") text = TitlesNode.Attributes["Name"].Value + ":" + result[0];
                    }
                    else if (TitlesNode.Attributes["Name"].Value == "入院日期") {
                        string tempIndate = na.GetValue(document, null).ToString();
                        text = TitlesNode.Attributes["Name"].Value + ":" + DateTime.Parse(tempIndate).ToString("yyyy-MM-dd");
                    }
                    infoTitle.Add(text);
                }
            }
            // 绘制病人基本信息
            float infoWidth = options.Width / infoTitle.Count;
            using (StringFormat infoFormat = new StringFormat())
            {
                infoFormat.Alignment = StringAlignment.Near;
                infoFormat.LineAlignment = StringAlignment.Center;
                for (int iCount = 0; iCount < infoTitle.Count; iCount++)
                {
                    string text = infoTitle[iCount];
                    if (string.IsNullOrEmpty(text) == false)
                    {
                        if (text.Contains("姓名"))
                        {
                            #region 姓名
                            if (options.Code == "dz")
                            {
                                RectangleF infoTextBounds = new RectangleF(
                                    options.Left + infoWidth * iCount + 20,
                                    options.Top + titleHeight,
                                    infoWidth,
                                    titleLineHeight);
                                g.DrawString(
                                    text,
                                    labelFont,
                                    Brushes.Black,
                                    infoTextBounds,
                                    infoFormat);

                            }
                            else
                            {
                                RectangleF infoTextBounds = new RectangleF(
                                    options.Left + infoWidth * iCount - 10,
                                    options.Top + titleHeight,
                                    infoWidth + 30,
                                    titleLineHeight);
                                g.DrawString(
                                    text,
                                    labelFont,
                                    Brushes.Black,
                                    infoTextBounds,
                                    infoFormat);
                            }
                            #endregion
                        }
                        else if (text.Contains("性别"))//性别长度特殊处理
                        {
                            #region 性别
                            if (options.Code == "yd")
                            {
                                RectangleF infoTextBounds = new RectangleF(
                                    options.Left + infoWidth * iCount - 30,
                                    options.Top + titleHeight,
                                    infoWidth,
                                    titleLineHeight);
                                g.DrawString(
                                    text,
                                    labelFont,
                                    Brushes.Black,
                                    infoTextBounds,
                                    infoFormat);
                            }
                            else
                            {
                                RectangleF infoTextBounds = new RectangleF(
                                    options.Left + infoWidth * iCount - 10,
                                    options.Top + titleHeight,
                                    infoWidth,
                                    titleLineHeight);
                                g.DrawString(
                                    text,
                                    labelFont,
                                    Brushes.Black,
                                    infoTextBounds,
                                    infoFormat);
                            }
                            #endregion
                        }
                        else if (text.Contains("年龄"))//年龄长度特殊处理
                        {
                            if (document.ShowType == "0")
                            {
                                #region 年龄
                                if (options.Code == "dz" || options.Code == "es")
                                {
                                    RectangleF infoTextBounds = new RectangleF(
        options.Left + infoWidth * iCount - 45,
        options.Top + titleHeight,
        infoWidth,
        titleLineHeight);
                                    g.DrawString(
                                        text,
                                        labelFont,
                                        Brushes.Black,
                                        infoTextBounds,
                                        infoFormat);
                                }
                                else if (options.Code == "yd")
                                {
                                    float tempY = 0.0f; float tempHeight = 0.0f;
                                    if (text.Length > 7) { tempY = titleHeight2; tempHeight = 2 * titleLineHeight; }
                                    else { tempY = titleHeight; tempHeight = titleLineHeight; }
                                    RectangleF infoTextBounds = new RectangleF(
        options.Left + infoWidth * iCount - 10,
        options.Top + tempY,
        infoWidth - 10,
        tempHeight);
                                    g.DrawString(
                                        text,
                                        labelFont,
                                        Brushes.Black,
                                        infoTextBounds,
                                        infoFormat);
                                }
                                else if (options.Code == "qz")
                                {
                                    RectangleF infoTextBounds = new RectangleF(
        options.Left + infoWidth * iCount - 35,
        options.Top + titleHeight,
        infoWidth,
        titleLineHeight);
                                    g.DrawString(
                                        text,
                                        labelFont,
                                        Brushes.Black,
                                        infoTextBounds,
                                        infoFormat);
                                }
                                else
                                {
                                    RectangleF infoTextBounds = new RectangleF(
            options.Left + infoWidth * iCount,
            options.Top + titleHeight,
            infoWidth,
            titleLineHeight);
                                    g.DrawString(
                                        text,
                                        labelFont,
                                        Brushes.Black,
                                        infoTextBounds,
                                        infoFormat);
                                }

                                #endregion
                            }
                        }
                        else if (text.Contains("科室") || text.Contains("科别"))//科室长度特殊处理
                        {
                            #region 科室或者科别
                            float tempY = 0.0f; float tempHeight = 0.0f;
                            if (text.Contains("->") || text.Length > 10) { tempY = titleHeight2; tempHeight = 2 * titleLineHeight; }
                            else { tempY = titleHeight; tempHeight = titleLineHeight; }
                            if (printType == 1)
                            {
                                RectangleF infoTextBounds = new RectangleF(
                                    options.Left + infoWidth * iCount - 140,
                                    options.Top + tempY,
                                    infoWidth + 90,
                                    tempHeight);
                                g.DrawString(
                                    text,
                                    labelFont,
                                    Brushes.Black,
                                    infoTextBounds,
                                    infoFormat);
                            }
                            else
                            {
                                if (options.Code == "yd" || options.Code == "es")
                                {
                                    float resuce = 0.0f;
                                    if (text.Length >= 10) resuce = 70f;
                                    else resuce = 70f;
                                    RectangleF infoTextBounds = new RectangleF(
                                        options.Left + infoWidth * iCount - resuce,
                                        options.Top + tempY,
                                        infoWidth + 50,
                                        tempHeight);
                                    g.DrawString(
                                        text,
                                        labelFont,
                                        Brushes.Black,
                                        infoTextBounds,
                                        infoFormat);
                                }
                                else if (options.Code == "qz")
                                {
                                    RectangleF infoTextBounds = new RectangleF(
                                        options.Left + infoWidth * iCount - 80,
                                        options.Top + tempY,
                                        infoWidth + 30,
                                        tempHeight);
                                    g.DrawString(
                                        text,
                                        labelFont,
                                        Brushes.Black,
                                        infoTextBounds,
                                        infoFormat);
                                }
                                else
                                {
                                    RectangleF infoTextBounds = new RectangleF(
            options.Left + infoWidth * iCount,
            options.Top + tempY,
            infoWidth + 60,
            tempHeight);
                                    g.DrawString(
                                        text,
                                        labelFont,
                                        Brushes.Black,
                                        infoTextBounds,
                                        infoFormat);
                                }
                            }
                            #endregion
                        }
                        else if (text.Contains("床号"))//床号长度特殊处理
                        {
                            #region 床号
                            float tempY = 0.0f; float tempHeight = 0.0f;
                            if (text.Contains("->") && text.Length >10) { tempY = titleHeight2; tempHeight = 2 * titleLineHeight;
                            text = text.Substring(0, 10) + "\n" + text.Substring(10, text.Length - 10);
                            }
                            else { tempY = titleHeight; tempHeight = titleLineHeight; }
                            if (printType == 1)
                            {
                                RectangleF infoTextBounds = new RectangleF(
options.Left + infoWidth * iCount - 60,
options.Top + tempY,
infoWidth,
tempHeight);
                                g.DrawString(
                                    text,
                                    labelFont,
                                    Brushes.Black,
                                    infoTextBounds,
                                    infoFormat);
                            }
                            else
                            {
                                RectangleF infoTextBounds = new RectangleF(
options.Left + infoWidth * iCount - 25,
options.Top + tempY,
infoWidth,
tempHeight);
                                g.DrawString(
                                    text,
                                    labelFont,
                                    Brushes.Black,
                                    infoTextBounds,
                                    infoFormat);
                            }
                            #endregion
                        }
                        else if (text.Contains("入院"))//入院长度特殊处理
                        {
                            #region 入院时间
                            if (printType == 1)
                            {
                                RectangleF infoTextBounds = new RectangleF();
                                if (options.Code == "es") //恩施入院时间稍作调整--往左偏移
                                {
                                    infoTextBounds = new RectangleF(
    options.Left + infoWidth * iCount - 160,
    options.Top + titleHeight,
    infoWidth + 120,
    titleLineHeight);
                                }
                                else
                                {
                                    infoTextBounds = new RectangleF(
    options.Left + infoWidth * iCount - 100,
    options.Top + titleHeight,
    infoWidth + 100,
    titleLineHeight);
                                }
                                g.DrawString(
                                    text,
                                    labelFont,
                                    Brushes.Black,
                                    infoTextBounds,
                                    infoFormat);
                            }
                            else
                            {
                                RectangleF infoTextBounds = new RectangleF(
options.Left + infoWidth * iCount - 35,
options.Top + titleHeight,
infoWidth + 75,
titleLineHeight);
                                g.DrawString(
                                    text,
                                    labelFont,
                                    Brushes.Black,
                                    infoTextBounds,
                                    infoFormat);
                            }
                            #endregion
                        }
                        else if (text.Contains("住院"))//住院号长度特殊处理
                        {
                            #region 住院号
                            RectangleF infoTextBounds = new RectangleF(
    options.Left + infoWidth * iCount - 15,
    options.Top + titleHeight,
    infoWidth + 55,
    titleLineHeight);
                            g.DrawString(
                                text,
                                labelFont,
                                Brushes.Black,
                                infoTextBounds,
                                infoFormat);
                            #endregion
                        }
                        else
                        {
                            RectangleF infoTextBounds = new RectangleF(
    options.Left + infoWidth * iCount,
    options.Top + titleHeight,
    infoWidth,
    titleLineHeight);
                            g.DrawString(
                                text,
                                labelFont,
                                Brushes.Black,
                                infoTextBounds,
                                infoFormat);
                        }

                    }//if
                }//for
            }//using
            titleHeight += titleLineHeight;


            // 页尾行总高度
            int footheight = 0;
            foreach (TitleLineInfo info in options.FooterLines)
            {
                if (info.ShowType == "" || info.ShowType.Contains(document.ShowType))
                {
                    footheight++;
                    if (info.ValueType == TitleLineValueType.FBreath) footheight++;
                }
            }

            float totalFooterLineHeight = titleLineHeight * (footheight);//此处针对页尾行呼吸占用两行设置  如需增加行  在此处添加

            // 页尾备注
            float footRemarkHeight = 0f;
            int RemarkCount = 0;
            foreach (FooterRemark info in options.FooterRemarks)
            {
                if (info.ShowType == document.ShowType) RemarkCount++;
            }
            if (RemarkCount > 0)
            {
                footRemarkHeight = titleLineHeight * (13 - footheight); //暂时13行时候，事件位置刚好
            }
            // 数据区域网格边界矩形
            RectangleF dataGridBounds = new RectangleF(
                options.Left + totalYAxisWidth,
                options.Top + titleHeight + titleLineHeight * trueIndex,
                options.Width - totalYAxisWidth,//- RightYAxisWidth,//此处中间网格整块列宽度为总宽度-左边栏目宽度-右边栏目宽度
                options.Height - totalHeaderLineHeight - totalFooterLineHeight - titleHeight - footRemarkHeight);
            // 绘制标题行网格竖线
            float dayStep = dataGridBounds.Width / options.NumOfDaysInOnePage;

            DateTime[] colDateTime = new DateTime[options.HeaderLines.Count];           
            // 绘制数据标题行
            int tempIndex = 0; 
            for (int lineIndex = 0; lineIndex < options.HeaderLines.Count; lineIndex++)
            {
                TitleLineInfo line = options.HeaderLines[lineIndex];
                //新生儿体温单不显示分娩日数
                string ShowType = line.ShowType;
                if (ShowType != "" && !ShowType.Contains(document.ShowType))
                {
                    continue;
                }
                else
                {
                    line.Top = options.Top + titleHeight + titleLineHeight * tempIndex;
                    // 绘制横线
                    g.DrawLine(
                        Pens.Black,
                        options.Left,
                        line.Top + titleLineHeight,
                        options.Left + options.Width,
                        line.Top + titleLineHeight);
                    // 标题边界
                    RectangleF titleRect = new RectangleF(
                        options.Left,
                        line.Top,
                        totalYAxisWidth,
                        titleLineHeight);
                    if (string.IsNullOrEmpty(line.Text) == false)
                    {
                        //新生儿体温单手术后日数变成出生日数
                        //if (document.ShowType == "1" && line.Text.Contains("手术后日数"))
                        //{
                        //    // 绘制标题文本
                        //    g.DrawString(
                        //        "出生日数",
                        //        labelFont,
                        //        Brushes.Black,
                        //        titleRect,
                        //        centerFormat);
                        //}
                        //else
                        //{
                            // 绘制标题文本
                            g.DrawString(
                                line.Text,
                                labelFont,
                                Brushes.Black,
                                titleRect,
                                centerFormat);
                        //}
                    }
                    tempIndex++;
                }           
                if (line.ValueType == TitleLineValueType.SerialDate)
                {
                    // 绘制日期系列
                    for (int dayIndex = 0; dayIndex < options.NumOfDaysInOnePage; dayIndex++)
                    {
                        DateTime dtm = startDate.AddDays(dayIndex);
                        colDateTime[lineIndex] = dtm;
                        //出院当页，日期一直显示
                        //if (maxDate != TemperatureDocument.NullDate)
                        //{
                        //    if (dtm > maxDate)
                        //    {
                        //        // 超出最大日期，不显示
                        //        break;
                        //    }
                        //}
                        string text = null;
                        if ((document.PageIndex == 0 && dayIndex == 0) || (dtm.Month == 1 && dtm.Day == 1))
                        {
                            // 跨年以及第一页的第一栏
                            text = dtm.ToString(options.BeginFormatString);
                        }
                        else if (dayIndex == 0)
                        {
                            // 如果是本序列的第一栏
                            text = dtm.ToString(options.DateFormatString);
                        }
                        else
                        {
                            //本月的第一天则显示对应日期
                            if (dtm.Day == 1)
                            {
                                text = dtm.ToString(options.DateFormatString);
                            }
                            else
                            {
                                // 否则只显示日数
                                text = dtm.Day.ToString();
                            }
                        }
                        g.DrawString(
                            text,
                            labelFont,
                            Brushes.Black,
                            new RectangleF(
                                dataGridBounds.Left + dayStep * dayIndex,
                                line.Top,
                                dayStep,
                                titleLineHeight),
                            centerFormat);
                    }//for
                }
                else if (line.ValueType == TitleLineValueType.HourTick)
                {
                    // 绘制小时刻数
                    float topFix = (titleLineHeight - labelFont.GetHeight(g)) / 2;
                    for (int dayIndex = 0; dayIndex < options.NumOfDaysInOnePage; dayIndex++)
                    {
                        for (int tickCount = 0; tickCount < options.HourTicks.Length; tickCount++)
                        {
                            int hour = int.Parse(options.HourTicks[tickCount].Split(':')[0].ToString());
                            Brush b = new SolidBrush(ColorTranslator.FromHtml(options.HourTickColors[tickCount]));//hour > 21 || hour < 8 ? Brushes.Red : Brushes.Black;
                            //目前用24小时制，注释以下3行代码
                            //if (hour > 12)
                            //{
                            //    hour = hour - 12;
                            //}
                            float tickStep = dayStep / options.HourTicks.Length;
                            // 计算边界
                            RectangleF tickRect = new RectangleF(
                                dataGridBounds.Left + dayStep * dayIndex + tickStep * tickCount,
                                line.Top,
                                tickStep,
                                titleLineHeight);
                            // 绘制时刻数
                            if (printType == 1)
                            {
                                g.DrawString(
    hour.ToString(),
    labelFont,
    b,
    hour >= 10 ? tickRect.X - 5 : tickRect.X + tickStep / 4 - 5,//修正偏移
    tickRect.Y + topFix);
                            }
                            else
                            {
                                g.DrawString(
    hour.ToString(),
    labelFont,
    b,
    hour >= 10 ? tickRect.X : tickRect.X + tickStep / 4,
    tickRect.Y + topFix);
                            }
                            // 绘制边框
                            g.DrawRectangle(
                                Pens.Black,
                                tickRect.Left,
                                tickRect.Top,
                                tickRect.Width,
                                tickRect.Height);
                        }//for
                    }//for
                }//else
            }//for
            // 绘制Y坐标轴内容
            for (int iCount = 0; iCount < options.YAxisInfos.Count; iCount++)
            {            
                if (options.YAxisInfos[iCount].Types != 2)
                {
                    //小单元格高度
                    float littleHeight = dataGridBounds.Height / (options.YSplitNum * 5 + options.YSplitLittleNum);
                    //此处区分疼痛评分列表和其它列表展示
                    if (options.YAxisInfos[iCount].Types != 1)
                    {
                        //心率左边栏名称、单位、刻度不展示
                        if (options.YAxisInfos[iCount].ValueMember != ValueMemberType.HeartRate)
                        {
                            YAxisInfo info = options.YAxisInfos[iCount];
                            for (int numTick = 0; numTick < options.YSplitNum; numTick++)
                            {
                                // 绘制Y轴刻度文本
                                RectangleF infoRect = new RectangleF();
                                if (options.Code == "yd" && options.YAxisInfos[iCount].ValueMember == ValueMemberType.Pluse && printType == 1)
                                {
                                    infoRect = new RectangleF(
   options.Left + info.ViewLeft + 15,
   dataGridBounds.Top + littleHeight * (numTick * 5 + options.YSplitLittleNum),//+ dataGridBounds.Height * numTick / options.YSplitNum,
   info.ViewWidth,
   titleLineHeight);
                                }
                                else if (options.Code == "yd" && options.YAxisInfos[iCount].ValueMember == ValueMemberType.Pluse)
                                {
                                    infoRect = new RectangleF(
   options.Left + info.ViewLeft + 5,
   dataGridBounds.Top + littleHeight * (numTick * 5 + options.YSplitLittleNum),// dataGridBounds.Height * numTick / options.YSplitNum,
   info.ViewWidth,
   titleLineHeight);
                                }
                                else
                                {
                                    infoRect = new RectangleF(
   options.Left + info.ViewLeft,
   dataGridBounds.Top + littleHeight * (numTick * 5 + options.YSplitLittleNum), //dataGridBounds.Height * numTick / options.YSplitNum,
   info.ViewWidth,
   titleLineHeight);
                                }
                                float numValue = info.MaxValue -
                                    (info.MaxValue - info.MinValue) * numTick / options.YSplitNum;
                                string text = numValue.ToString();
                                string textUnit = "";
                                if (numTick == 0 && options.YSplitLittleNum == 0)
                                {
                                    // 第一行为标题
                                    text = info.Title;
                                    // 第二行为单位
                                    //单位位置设定
                                    RectangleF infoRectUnit = new RectangleF();
                                    if (options.Code == "yd" && options.YAxisInfos[iCount].ValueMember == ValueMemberType.Pluse && printType == 1)
                                    {
                                        infoRectUnit = new RectangleF(
                                           options.Left + info.ViewLeft + 15,
                                           dataGridBounds.Top + titleLineHeight,
                                           info.ViewWidth,
                                           titleLineHeight);
                                    }
                                    else if (options.Code == "yd" && options.YAxisInfos[iCount].ValueMember == ValueMemberType.Pluse)
                                    {
                                        infoRectUnit = new RectangleF(
                                           options.Left + info.ViewLeft + 5,
                                           dataGridBounds.Top + titleLineHeight,
                                           info.ViewWidth,
                                           titleLineHeight);
                                    }
                                    else
                                    {
                                        infoRectUnit = new RectangleF(
   options.Left + info.ViewLeft,
   dataGridBounds.Top + titleLineHeight,
   info.ViewWidth,
   titleLineHeight);
                                    }
                                    textUnit = info.Unit;
                                    // 绘制单位
                                    g.DrawString(
                                        textUnit,
                                        labelFont,
                                        Brushes.Black,
                                        infoRectUnit,
                                        centerFormat);
                                }
                                //针对头部有多小格配置 名称单位配置
                                else if (numTick == 0 && options.YSplitLittleNum != 0)
                                {
                                    // 第一行为标题
                                    RectangleF infoRectTitle = new RectangleF();
                                    if (options.Code == "yd" && options.YAxisInfos[iCount].ValueMember == ValueMemberType.Pluse && printType == 1)
                                    {
                                        infoRectTitle = new RectangleF(
                                           options.Left + info.ViewLeft + 15,
                                           dataGridBounds.Top,//+ titleLineHeight,
                                           info.ViewWidth,
                                           titleLineHeight);
                                    }
                                    else if (options.Code == "yd" && options.YAxisInfos[iCount].ValueMember == ValueMemberType.Pluse)
                                    {
                                        infoRectTitle = new RectangleF(
                                           options.Left + info.ViewLeft + 5,
                                           dataGridBounds.Top,//+ titleLineHeight,
                                           info.ViewWidth,
                                           titleLineHeight);
                                    }
                                    else
                                    {
                                        infoRectTitle = new RectangleF(
   options.Left + info.ViewLeft,
   dataGridBounds.Top,//+ titleLineHeight,
   info.ViewWidth,
   titleLineHeight);
                                    }
                                    // 第二行为单位
                                    //单位位置设定
                                    RectangleF infoRectUnit = new RectangleF();
                                    if (options.Code == "yd" && options.YAxisInfos[iCount].ValueMember == ValueMemberType.Body_Temperature && printType == 1)
                                    {
                                        infoRectUnit = new RectangleF(
                                           options.Left + info.ViewLeft + 15,
                                           dataGridBounds.Top + titleLineHeight,
                                           info.ViewWidth,
                                           titleLineHeight);
                                    }
                                    else if (options.Code == "yd" && options.YAxisInfos[iCount].ValueMember == ValueMemberType.Body_Temperature)
                                    {
                                        infoRectUnit = new RectangleF(
                                           options.Left + info.ViewLeft + 5,
                                           dataGridBounds.Top + titleLineHeight,
                                           info.ViewWidth,
                                           titleLineHeight);
                                    }
                                    else
                                    {
                                        infoRectUnit = new RectangleF(
   options.Left + info.ViewLeft,
   dataGridBounds.Top + titleLineHeight,
   info.ViewWidth,
   titleLineHeight);
                                    }
                                    // 绘制文本
                                    g.DrawString(
                                        info.Title,
                                        labelFont,
                                        Brushes.Black,
                                        infoRectTitle,
                                        centerFormat);
                                    textUnit = info.Unit;
                                    // 绘制单位
                                    g.DrawString(
                                        textUnit,
                                        labelFont,
                                        Brushes.Black,
                                        infoRectUnit,
                                        centerFormat);
                                }
                                //else if (numTick == options.YSplitNum - 1)
                                //{
                                //    // 最后一行的位置要向上移动一行
                                //    infoRect.Offset(0, -titleLineHeight);
                                //}
                                else
                                {
                                    // 中间的要向上移动半行
                                    infoRect.Offset(0, -titleLineHeight / 2);
                                }
                                if (string.IsNullOrEmpty(text) == false)
                                {
                                    // 绘制文本
                                    g.DrawString(
                                        text,
                                        labelFont,
                                        Brushes.Black,
                                        infoRect,
                                        centerFormat);
                                }
                            }//for
                            // 绘制Y轴竖线
                            ////如果后一个选项为疼痛评分，则左边不绘制竖线
                            g.DrawLine(
                                Pens.Black,
                                options.Left + info.ViewLeft,//+ info.ViewWidth,
                                dataGridBounds.Top,
                                options.Left + info.ViewLeft,//+ info.ViewWidth,
                                dataGridBounds.Bottom);
                        }
                    }//if
                    else//此处为疼痛评分小列表
                    {
                        YAxisInfo info = options.YAxisInfos[iCount];
                        for (int numTick = 0; numTick < options.YSplitNum; numTick++)
                        {
                            // 绘制Y轴刻度文本
                            RectangleF infoRect = new RectangleF(
                               options.Left + info.ViewLeft,
                               dataGridBounds.Top + dataGridBounds.Height * numTick / options.YSplitNum,
                               info.ViewWidth,
                               titleLineHeight);
                            infoRect.Offset(0, -titleLineHeight/2);
                            string text;// = numValue.ToString();
                            if (numTick == options.YSplitNum - 1 || numTick == options.YSplitNum - 2)
                            {
                                float cTop = infoRect.Top + 10; //+ 10; //= infoRect.Top + 3;
                                float fh = labelFont.GetHeight(g);//labelFont.GetHeight(g);
                                for (int j = 0; j < 5; j++)
                                {
                                    float numValue = info.MaxValue -
        (info.MaxValue - info.MinValue) * numTick / options.YSplitNum;
                                    float splitNum = numValue - (info.MaxValue -
        (info.MaxValue - info.MinValue) * (numTick + 1) / options.YSplitNum);
                                    numValue = numValue - (splitNum / 5) * j;
                                    text = numValue.ToString();
                                    if (text == "1")//追加0
                                    {
                                        g.DrawString(
                                            text,
                                            labelFont,
                                            Brushes.Black,
                                            infoRect.X,
                                            cTop);
                                        cTop = cTop + fh;
                                        g.DrawString(
                                            "0",
                                            labelFont,
                                            Brushes.Black,
                                            infoRect.X,
                                            cTop);
                                    }
                                    else
                                    {
                                        g.DrawString(
                                            text,
                                            labelFont,
                                            Brushes.Black,
                                            infoRect.X,
                                            cTop);
                                        cTop = cTop + fh;
                                    }
                                }
                            }
                            else if (numTick == options.YSplitNum - 3)
                            {
                                text = info.Title;
                                float fh = labelFont.GetHeight(g);//12
                                float cTop = infoRect.Top + 10; ;
                                foreach (char c in text)
                                {
                                    string txt = c.ToString();
                                    g.DrawString(
                                        txt,
                                        labelFont,
                                        Brushes.Black,
                                        infoRect.X,
                                        cTop);
                                    cTop = cTop + fh;
                                }//foreach
                            }

                        }//for
                    }
                }//if
            }//for
            // 绘制Y坐标轴区域大边框
            g.DrawLine(
                Pens.Black,
                options.Left,
                dataGridBounds.Bottom,
                dataGridBounds.Left,
                dataGridBounds.Bottom);
            // 绘制数据区域大网格线
            DrawGrid(
                g,
                dataGridBounds,
                options.NumOfDaysInOnePage * options.HourTicks.Length,
                options.YSplitNum * 5 + options.YSplitLittleNum,
                Pens.Black,
                options.YSplitLittleNum,
                options.YSplitLittleNums
                );
            //获取数据区域单元格高度（用于绘制事件）
            string CellHeight = (dataGridBounds.Height / (options.YSplitNum * 5 + options.YSplitLittleNum)).ToString();
            string CellWidth = (dataGridBounds.Width / (options.NumOfDaysInOnePage * options.HourTicks.Length)).ToString();
            // 清空状态
            foreach (YAxisInfo info in options.YAxisInfos)
            {
                info.LastPoint = new PointF(float.NaN, float.NaN);
            }

            //各区域坐竖线X坐标
            float[] linePosX = new float[options.NumOfDaysInOnePage];
            //各区域是否有数据
            bool[] existData = new bool[options.NumOfDaysInOnePage];

            // 绘制大竖线
            Pen p_v = new Pen(Color.Red, 2);//配置项
            if (printType == 1)
            {
                p_v = new Pen(Color.Red, 5);
            }

            for (int lineIndex = 0; lineIndex < options.NumOfDaysInOnePage; lineIndex++)//lineIndex <= options.NumOfDaysInOnePage; lineIndex++)
            {
                if (lineIndex != 0)
                {
                    g.DrawLine(
                        p_v,
                        //lineIndex == 0 || lineIndex == options.NumOfDaysInOnePage ? Pens.Black : Pens.Red,
                        dataGridBounds.Left + dayStep * lineIndex,
                        options.Top + titleHeight,
                        dataGridBounds.Left + dayStep * lineIndex,
                        options.Top + options.Height - footRemarkHeight);
                }//for
                else
                {
                    g.DrawLine(
                        Pens.Black,
                        dataGridBounds.Left + dayStep * lineIndex,
                        options.Top + titleHeight,
                        dataGridBounds.Left + dayStep * lineIndex,
                        options.Top + options.Height - footRemarkHeight);
                }
                linePosX[lineIndex] = dataGridBounds.Left + dayStep * lineIndex;
                existData[lineIndex] = false;
            }
            #region 绘制数据点和线
            string lastLine = "0";
            bool esflag = true;  //记录恩施---体温数据是否在竖线上
            foreach (Measure record in document.Measures)
            {
                List<PointF> pointList = new List<PointF>();//用来记录绘制短绌的不规则图形的坐标
                List<PointF> plusepointList = new List<PointF>();//用来记录脉搏的坐标
                List<PointF> heartRatepointList = new List<PointF>();//用来记录心率的坐标
                List<PointF> coincideList = new List<PointF>();//用来记录需要重合的坐标
                string[] coincide = new string[2]; //记录重合信息 coincide[0] 体温与脉搏 coincide[1] 心率与脉搏
                //List<PointF> pointList = new List<PointF>();//用来记录绘制短绌的不规则图形的坐标
                int dayIndex = (record.ValueDate - DateTime.Parse(startDate.ToShortDateString())).Days;
                if (dayIndex < 0)
                {
                    // 过早的记录不显示
                    continue;
                }
                if (dayIndex >= options.NumOfDaysInOnePage)
                {
                    // 超出本页最后日期，后续记录不显示
                    break;
                }
                // 获得时刻点
                int hourTickIndex = -1;
                int hourflag = 0;//时间点是否在节点上
                for (int hour = 0; hour < options.HourTicks.Length; hour++)
                {
                    #region 注释的代码
                    //if (record.ValueTime < options.HourTicks[hour])
                    //{
                    //    hourTickIndex = hour - 1;
                    //    break;
                    //}
                    #endregion
                    if (record.ValueTime == options.HourTicks[hour])
                    {
                        hourTickIndex = hour;
                        hourflag = 1;
                        break;
                    }
                }
                #region 当时刻表小于0
                if (hourTickIndex < 0)
                {
                    //当时间点不在节点上，显示在两个节点之间
                    //判断时间点是否比最后的时间节点大
                    DateTime dt1 = DateTime.Parse(System.DateTime.Now.ToShortDateString() + " " + options.HourTicks[options.HourTicks.Length - 1]);
                    DateTime dt2 = DateTime.Parse(System.DateTime.Now.ToShortDateString() + " " + record.ValueTime);
                    
                    if (dt2 > dt1)
                    {
                        hourTickIndex = options.HourTicks.Length;
                    }
                    else
                    {
                        for (int hour = 0; hour < options.HourTicks.Length; hour++)
                        {
                            dt1 = DateTime.Parse(System.DateTime.Now.ToShortDateString() + " " + options.HourTicks[hour]);
                            if (dt2 <= dt1)
                            {
                                hourTickIndex = hour;
                                break;
                            }
                        }
                    }
                }
                #endregion
                #region 计算当前数据点X坐标
                float pointX = 0.0f;
                if (hourflag == 1) //时间点在节点上
                {
                    pointX = dataGridBounds.Left +
                        (dayIndex * options.HourTicks.Length + hourTickIndex + 0.5f)
                        * (dayStep / (float)options.HourTicks.Length);
                }
                else
                { //节点之外的时间点
                    DateTime dt1 = DateTime.Parse(System.DateTime.Now.ToShortDateString() + " " + options.HourTicks[hourTickIndex]);
                    DateTime dt2 = DateTime.Parse(System.DateTime.Now.ToShortDateString() + " " + record.ValueTime);
                    pointX = dataGridBounds.Left +
                        (dayIndex * options.HourTicks.Length + hourTickIndex + 0.5f)
                        * (dayStep / (float)options.HourTicks.Length) -
                        (float)((dt1 - dt2).TotalMinutes) / 30 * (dayStep / (float)options.HourTicks.Length) / 8;
                }
                #endregion

                #region 绘制数据内容及连线
                PointF Point_Body_Temperature = new PointF();
                PointF Point_FT = new PointF();
                //当次展示值
                float TempValue = 0f;
                foreach (YAxisInfo info in options.YAxisInfos)
                {

                    float Value = info.GetValue(record, TempValue, options.TopTemp);//此处耳温、腋温、口温、肛温、起搏器特殊字符已过滤

                    if (TemperatureDocument.IsNullValue(Value))
                    {
                        //info.LastPoint = new PointF(float.NaN, float.NaN);
                    }
                    else
                    {
                        float pointY = 1.0f - (Value - info.MinValue) / ((options.YSplitNum * 5 + options.YSplitLittleNum) * (info.MaxValue - info.MinValue) / (options.YSplitNum * 5));
                        //float pointY = 1.0f - (Value - info.MinValue) / (info.MaxValue - info.MinValue);
                        pointY = dataGridBounds.Top + dataGridBounds.Height * pointY;
                        PointF point = new PointF(pointX, pointY);

                        #region 优先画数据点符号
                        //获取几种体温状态（衍生---保存数据的其他状态--呼吸机，起搏器等）
                        string Temperature = info.GetTemperatureValue(record);
                        float SymbolSize = 0.0f;
                        #region CHECK 体温与脉搏重合情况
                        //Check体温与脉搏重合
                        if (record.Body_Temperature != null && record.Pluse != null)
                        {
                            if (info.ValueMember == ValueMemberType.Pluse || info.ValueMember == ValueMemberType.Body_Temperature)
                            {
                                coincideList.Add(point);
                                if (coincideList.Count == 2)
                                {
                                    //计算2个坐标点之间的距离
                                    double value = Math.Sqrt(Math.Abs(coincideList[0].X - coincideList[1].X) * Math.Abs(coincideList[0].X - coincideList[1].X) + Math.Abs(coincideList[0].Y - coincideList[1].Y) * Math.Abs(coincideList[0].Y - coincideList[1].Y));
                                    if (value < 0.0005)
                                    {
                                        coincide[0] = "1";
                                    }
                                    else
                                    {
                                        coincide[0] = "";
                                    }
                                    //coincide[0] = coincideList[0] == coincideList[1] ? "1":"";
                                }
                            }
                        }
                        if (record.HeartRate != null && record.Pluse != null &&
                            record.HeartRate == record.Pluse) //判断心率和脉搏重叠  共用一个Y轴，直接判断值
                        {
                            coincide[1] = "1";
                        }
                        #endregion
                        
                        // 绘制数据点符号
                        DrawSymbol(g, point.X, point.Y, info, options, Temperature, document, coincide, out SymbolSize);//对符号进行强转
                        #endregion
                        
                        //点线之间留有空隙
                        PointF tempLast, tempNow;
                        //float tempx = 0.0f;
                        double temptan = (point.Y - info.LastPoint.Y) / (point.X - info.LastPoint.X);
                        double TwoPointWidth = Math.Abs(point.X - info.LastPoint.X);
                        double TwoPointHeight = Math.Abs(point.Y - info.LastPoint.Y);
                        double TwoPointLength = Math.Sqrt((TwoPointWidth * TwoPointWidth) + (TwoPointHeight * TwoPointHeight)); //计算两点间长度

                        if (float.IsNaN(info.LastPoint.X) == false)
                        {
                            if (info.LastSymbolSize > 0) tempLast = getPoint(info.LastPoint.X, info.LastPoint.Y, info.LastSymbolSize, info.LastPoint.X, info.LastPoint.Y, point.X, point.Y, 1);
                            else tempLast = info.LastPoint;

                            if (SymbolSize > 0) tempNow = getPoint(point.X, point.Y, SymbolSize, info.LastPoint.X, info.LastPoint.Y, point.X, point.Y, 0);
                            else tempNow = point;
                        }
                        else {
                            tempLast = info.LastPoint;
                            tempNow = point;
                        }
                        //if (temptan >= 0)
                        //{
                        //    //计算旧坐标
                        //    tempx = SymbolSize / TwoPointLength * TwoPointWidth + info.LastPoint.X;
                        //    tempy = SymbolSize / TwoPointLength * TwoPointHeight + info.LastPoint.Y;
                        //    tempLast = new PointF((float)tempx, (float)tempy);
                        //    //计算新坐标
                        //    tempx = point.X - SymbolSize / TwoPointLength * TwoPointWidth;
                        //    tempy = point.Y - SymbolSize / TwoPointLength * TwoPointHeight;
                        //    tempNow = new PointF((float)tempx, (float)tempy);
                        //}
                        //else {
                        //    //计算旧坐标
                        //    tempx = SymbolSize / TwoPointLength * TwoPointWidth + info.LastPoint.X;
                        //    tempy = info.LastPoint.Y - SymbolSize / TwoPointLength * TwoPointHeight;
                        //    tempLast = new PointF((float)tempx, (float)tempy);
                        //    //计算新坐标
                        //    tempx = point.X - SymbolSize / TwoPointLength * TwoPointWidth;
                        //    tempy = SymbolSize / TwoPointLength * TwoPointHeight + point.Y;
                        //    tempNow = new PointF((float)tempx, (float)tempy);
                        //}

                        #region 废弃代码---连线之间有空隙
                        //if (temptan < -2) tempx = 4;
                        //else if (temptan >= -2 && temptan < -1) tempx = 8;
                        //else if (temptan >= -1 && temptan <= -0.5) tempx = 12;
                        //else if (temptan > -0.5 && temptan < 0) tempx = 16;
                        //else if (temptan < 0.5) tempx = 16;
                        //else if (temptan >= 0.5 && temptan <= 1) tempx = 12;
                        //else if (temptan > 1 && temptan <= 2) tempx = 8;
                        //else tempx = 4;
                        //float tempy = tempx * (point.Y - info.LastPoint.Y) / (point.X - info.LastPoint.X);  //tan函数，根据斜率以及X差值计算对应Y差值
                        #endregion
                        //连线特殊处理
                        if (options.Line == "1")
                        {
                            if (printType == 1)
                            {
                                if (float.IsNaN(info.LastPoint.X) == false && record.Line != null && record.Line == "1")// 若上一个数据点存在
                                {
                                    
                                    Pen pen = new Pen(info.SymbolColor, 4);

                                    if (options.Code == "es" && info.ValueMember == ValueMemberType.Pluse
                                         && esflag == false)
                                    {
                                        if (lastLine == "1")
                                        {
                                            //tempLast = info.LastPoint;
                                            //tempNow = point;
                                            g.DrawLine(pen, tempLast, tempNow);
                                        }
                                    }
                                    else
                                    {

                                        //if (options.Space == 1) //判断点线之间是否留有空隙
                                        //{
                                        //    tempLast = new PointF(info.LastPoint.X + 20, info.LastPoint.Y + tempy);
                                        //    tempNow = new PointF(point.X - 20, point.Y - tempy);
                                        //}
                                        //else
                                        //{
                                        //tempLast = info.LastPoint;
                                        //tempNow = point;
                                        //}
                                        g.DrawLine(pen, tempLast, tempNow);
                                    }
                                    
                                }
                            }
                            else
                            {
                                if ((float.IsNaN(info.LastPoint.X) == false && record.Line != null && record.Line == "1") ||
                                    (options.Code == "es" && info.ValueMember == ValueMemberType.Pluse && esflag == false))
                                {
                                    // 若上一个数据点存在
                                    Pen pen = new Pen(info.SymbolColor, 2);
                                    //g.DrawLine(pen, info.LastPoint, point);
                                    if (options.Code == "es" && info.ValueMember == ValueMemberType.Pluse
                                         && esflag == false)
                                    {
                                        if (lastLine == "1" && record.Line == "1")
                                        {
                                            //tempLast = info.LastPoint;
                                            //tempNow = point;
                                            g.DrawLine(pen, tempLast, tempNow);
                                        }
                                        esflag = true;
                                    }
                                    else
                                    {
                                        g.DrawLine(pen, tempLast, tempNow);
                                    }
                                }
                            }
                        }
                        else
                        {
                            if (printType == 1)
                            {
                                if (float.IsNaN(info.LastPoint.X) == false && (point.X - info.LastPoint.X) < 280)
                                {
                                    // 若上一个数据点存在,并且两点之间时间不超24小时则绘制连线
                                    Pen pen = new Pen(info.SymbolColor, 4);
                                    //g.DrawLine(pen, info.LastPoint, point);
                                    //tempLast = info.LastPoint;
                                    //tempNow = point;
                                    g.DrawLine(pen, tempLast, tempNow);
                                }
                            }
                            else
                            {
                                if (float.IsNaN(info.LastPoint.X) == false && (point.X - info.LastPoint.X) < 90)
                                {
                                    // 若上一个数据点存在,并且两点之间时间不超24小时则绘制连线
                                    Pen pen = new Pen(info.SymbolColor, 2);
                                    //g.DrawLine(pen, info.LastPoint, point);
                                    //tempLast = info.LastPoint;
                                    //tempNow = point;
                                    g.DrawLine(pen, tempLast, tempNow);
                                }
                            }
                        }                        
                        
                        //如果心率跟脉搏不一样的时候实现短绌
                        if (record.Pluse != null && record.HeartRate != null)
                        {
                            //脉搏
                            if (info.ValueMember == ValueMemberType.Pluse)
                            {
                                if (float.IsNaN(info.LastPoint.X) == false && float.IsNaN(info.LastPoint.Y) == false)
                                {
                                    if (plusepointList.Count > 0)
                                    {
                                        if (DistinctPoint(plusepointList, info.LastPoint))
                                        {
                                            plusepointList.Add(info.LastPoint);
                                        }
                                    }
                                    else
                                    {
                                        plusepointList.Add(info.LastPoint);
                                    }

                                }
                                if (plusepointList.Count > 0)
                                {
                                    if (DistinctPoint(plusepointList, point))
                                    {
                                        plusepointList.Add(point);
                                    }
                                }
                                else
                                {
                                    plusepointList.Add(point);
                                }
                            }
                            //心率
                            if (info.ValueMember == ValueMemberType.HeartRate)
                            {
                                if (float.IsNaN(info.LastPoint.X) == false && float.IsNaN(info.LastPoint.Y) == false)
                                {
                                    if (heartRatepointList.Count > 0)
                                    {
                                        if (DistinctPoint(heartRatepointList, info.LastPoint))
                                        {
                                            heartRatepointList.Add(info.LastPoint);
                                        }
                                    }
                                    else
                                    {
                                        heartRatepointList.Add(info.LastPoint);
                                    }

                                }
                                if (heartRatepointList.Count > 0)
                                {
                                    if (DistinctPoint(heartRatepointList, point))
                                    {
                                        heartRatepointList.Add(point);
                                    }
                                }
                                else
                                {
                                    heartRatepointList.Add(point);
                                }
                            }                    
                        }                    
                        info.LastPoint = point;
                        info.LastSymbolSize = SymbolSize;
                       
                        //此处体温和降温的两个点需做成通用配置
                        if (info.ValueMember == ValueMemberType.Body_Temperature)
                        {
                            TempValue = Value;
                            Point_Body_Temperature = point;
                            //低于35度绘制下箭头
                            if (Value < 35)
                            {
                                Color arrow = ColorTranslator.FromHtml(options.ArrowColor);
                                Pen p = new Pen(arrow, 3);
                                p.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;//恢复实线  
                                p.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor;//定义线尾的样式为箭头  
                                g.DrawLine(p, point.X, point.Y, point.X, point.Y + 30);
                            }
                        }
                        else if (info.ValueMember == ValueMemberType.FT)
                        {
                            Point_FT = point;

                        }
                    }
                }//foreach YAxisInfo
                #endregion
                XmlNodeList YAxisInfosNodeList = document.Options.configXml.SelectNodes("TemperatureDocument/YAxisInfos/YAxisInfo");
                foreach (XmlNode YAxisInfosNode in YAxisInfosNodeList)
                {
                    #region 上事件
                    if (YAxisInfosNode.Attributes["Id"].Value == "MemoIn" && YAxisInfosNode.Attributes["IsShow"].Value == "1")
                    {
                        bool isShow = true;
                        if (options.Code == "yd" && (string.IsNullOrEmpty(record.MemoIn) == false && (record.MemoIn.Contains("小结") || record.MemoIn.Contains("总结"))))
                        {
                            isShow = false;
                        }
                        if (string.IsNullOrEmpty(record.MemoIn) == false && !record.MemoIn.Contains("正常") && isShow == true)
                        {
                            // 绘制竖的提示文字
                            SizeF cs = g.MeasureString(
                                "##",
                                labelFont,
                                10000,
                                StringFormat.GenericTypographic);
                            float fh = 0f ;//大小修正
                            //当Showtype为1表示新生儿,将入院事件改成出生事件
                            fh += Convert.ToSingle(CellHeight);
                            if (document.ShowType == "1" && options.Code == "yd") //延大产科
                            {
                                if (record.MemoIn.Contains("入院"))
                                {
                                    string memoInYuan = record.MemoIn;
                                    record.MemoIn = memoInYuan.Replace("入院", "入科");
                                }
                                else if (record.MemoIn.Contains("手术"))
                                {
                                    string memoInYuan = record.MemoIn;
                                    record.MemoIn = memoInYuan.Replace("手术", "出生");
                                }
                            }
                            float cTop = MemoIn + 3; //dataGridBounds.Top + 3;
                            float borderTop = MemoIn + 3;
                            string tempMemoIn = record.MemoIn.Split(';')[0];
                            if (!options.MemoTimeShow.Contains(tempMemoIn.Split('-')[0])) //事件的时间是否需要显示
                                tempMemoIn = tempMemoIn.Split('-')[0];
                            foreach (char c in tempMemoIn)
                            {
                                string txt = c.ToString();
                                if (c == '-')
                                {
                                    if (options.Code == "qz") continue;
                                    else txt = "|";
                                }
                                g.DrawString(
                                    txt,
                                    labelFont,
                                    Brushes.Red,
                                    pointX - cs.Width / 2,
                                    cTop);
                                cTop = cTop + fh;
                            }//foreach

                            if (record.MemoIn.Contains("出院"))
                            {
                                for (int i = 0; i < linePosX.Length - 1; i++)
                                {
                                    try
                                    {
                                        bool isLast = false;
                                        if (i == linePosX.Length - 1)
                                        {
                                            isLast = true;
                                        }
                                        if (linePosX[i] <= (pointX - cs.Width / 2) && (isLast || (pointX - cs.Width / 2) <= linePosX[i + 1]))
                                        {
                                            for (int j = 0; j <= i; j++)
                                            {
                                                existData[j] = true;
                                            }
                                            break;
                                        }
                                    }
                                    catch(Exception) {
                                       
                                    }
                                }
                            }

                            //根据配置是否显示边框
                            if (YAxisInfosNode.Attributes["IsShowBorder"].Value == "1")
                            {
                                Pen p = new Pen(ColorTranslator.FromHtml(YAxisInfosNode.Attributes["BorderColor"].Value), 2);
                                //绘制下事件边框
                                g.DrawRectangle(
                                                p,
                                                pointX - cs.Width / 2,
                                                borderTop,
                                                fh,
                                                fh * record.MemoIn.Length);
                            }
                        }
                    }
                    #endregion
                    #region 下事件
                    else if (YAxisInfosNode.Attributes["Id"].Value == "MemoUp" && YAxisInfosNode.Attributes["IsShow"].Value == "1")
                    {
                        if (string.IsNullOrEmpty(record.MemoUp) == false)
                        {
                            // 绘制竖的提示文字
                            SizeF cs = g.MeasureString(
                                "##",
                                labelFont,
                                10000,
                                StringFormat.GenericTypographic);
                            float fh = labelFont.GetHeight(g) + Convert.ToSingle(1.5);//大小修正
                            float uTop = MemoUp + 3;
                            float borderTop = MemoUp + 3;
                            foreach (char c in record.MemoUp)
                            {
                                string txt = c.ToString();
                                if (c == '-')
                                {
                                    txt = "|";
                                }
                                g.DrawString(
                                    txt,
                                    labelFont,
                                    Brushes.Blue,
                                    pointX - cs.Width / 2,
                                    uTop);
                                uTop = uTop + fh;
                            }//foreach
                            //根据配置是否显示边框
                            if (YAxisInfosNode.Attributes["IsShowBorder"].Value == "1")
                            {
                                Pen p = new Pen(ColorTranslator.FromHtml(YAxisInfosNode.Attributes["BorderColor"].Value), 2);
                                //绘制下事件边框
                                g.DrawRectangle(
                                                p,
                                                pointX - cs.Width / 2,
                                                borderTop,
                                                fh,
                                                fh * record.MemoUp.Length);
                            }
                        }
                    }
                    #endregion
                }
                //绘制体温和降温连线
                if (Point_FT != new PointF(0.0f, 0.0f))
                {
                    // 若上一个数据点存在则绘制连线
                    Pen p = new Pen(Color.Red, 2);
                    if (printType == 1)
                    {
                        p = new Pen(Color.Red, 4);
                    }
                    p.DashStyle = DashStyle.Dot;
                    g.DrawLine(p, Point_Body_Temperature, Point_FT);
                }
                //实现短绌画斜线的功能
                if (plusepointList.Count >1 || heartRatepointList.Count > 1)
                {
                    //判断出两个点都和现前面一次的心率或者脉搏连起来
                    if (plusepointList.Count == 2 && heartRatepointList.Count==1)
                    {
                        Pen pen = new Pen(Color.Red, 2);
                        g.DrawLine(pen, plusepointList[0], heartRatepointList[0]);
                    }
                    if (plusepointList.Count == 1 && heartRatepointList.Count == 2)
                    {
                        Pen pen = new Pen(Color.Red, 2);
                        g.DrawLine(pen, plusepointList[0], heartRatepointList[0]);
                    }
                    //判断不规则图形各个点的排序
                    if (plusepointList[0].Y > heartRatepointList[0].Y) 
                    {
                        pointList.AddRange(plusepointList);
                        for (int i = heartRatepointList.Count-1; i >=0; i--)
                        {
                             pointList.Add(heartRatepointList[i]);
                        }
                        DrawPolygon(g, pointList.ToArray());
                    }
                    else if(plusepointList[0].Y <heartRatepointList[0].Y)
                    {
                        pointList.AddRange(heartRatepointList);
                        for (int i = plusepointList.Count - 1; i >= 0; i--)
                        {
                            pointList.Add(plusepointList[i]);
                        }
                        DrawPolygon(g, pointList.ToArray()); 
                    }
                    else if (plusepointList[0].Y == heartRatepointList[0].Y)
                    {
                        pointList.AddRange(heartRatepointList);
                        for (int i = plusepointList.Count - 1; i >0; i--)
                        {
                            pointList.Add(plusepointList[i]);
                        }
                        DrawPolygon(g, pointList.ToArray()); 
                    }
                }

                #region 恩施医院特殊需求，记录当前的时间是否在节点上，如果不在节点上，记录本次的是否连线作为下次判断脉搏的依据
                for (int hour = 0; hour < options.HourTicks.Length; hour++)
                {
                    if (record.ValueTime == options.HourTicks[hour])
                    {
                        esflag = true;
                        break;
                    }
                    if (hour == options.HourTicks.Length - 1)
                    {
                        esflag = false;
                    }
                }
                if (options.Code == "es" && esflag == false)
                {
                    lastLine = record.Line;
                }
                #endregion
            }//foreach Measure
           
            #endregion
            // 绘制数据标题行
            tempIndex = 0; 
            for (int lineIndex = 0; lineIndex < options.HeaderLines.Count; lineIndex++)
            {
                TitleLineInfo line = options.HeaderLines[lineIndex];
                if (line.ShowType != "" && !line.ShowType.Contains(document.ShowType))
                {
                    continue;
                }
                else
                {
                    line.Top = options.Top + titleHeight + titleLineHeight * tempIndex;
                    if (line.ValueType == TitleLineValueType.InDayIndex)
                    {
                        // 绘制第几天数
                        if (line.RuntimeStartDate != TemperatureDocument.NullDate)
                        {
                            for (int dayIndex = 0; dayIndex < options.NumOfDaysInOnePage; dayIndex++)
                            {
                                // 计算当前日期
                                DateTime dtm = Convert.ToDateTime(startDate.ToString("yyyy-MM-dd 00:00:00")).AddDays(dayIndex);
                                if (maxDate != TemperatureDocument.NullDate)
                                {
                                    if (dtm > maxDate)
                                    {
                                        // 超出最大日期，不显示
                                        break;
                                    }
                                }
                                // 获得时间差
                                TimeSpan span = dtm - line.RuntimeStartDate;
                                if (span.Days >= 0)
                                {
                                    if (existData[dayIndex] || WhetherAllFalse(existData, dtm))
                                    {
                                        string text = Convert.ToString(span.Days + options.InDateBeginDay);//1);
                                        g.DrawString(
                                            text,
                                            labelFont,
                                            Brushes.Black,
                                            new RectangleF(
                                                dataGridBounds.Left + dayStep * dayIndex,
                                                line.Top,
                                                dayStep,
                                                titleLineHeight),
                                            centerFormat);
                                    }
                                }
                            }//for
                        }//if
                    }//else if
                    else if (line.ValueType == TitleLineValueType.DayIndex || line.ValueType == TitleLineValueType.ChildBirthDay)//手术后或产后天数
                    {
                        // 绘制第几天数
                        if (line.InRuntimeStartDate != null)
                        {
                            for (int dayIndex = 0; dayIndex < options.NumOfDaysInOnePage; dayIndex++)
                            {
                                // 计算当前日期
                                DateTime dtm = Convert.ToDateTime(startDate.ToString("yyyy-MM-dd 00:00:00")).AddDays(dayIndex);
                                if (maxDate != TemperatureDocument.NullDate)
                                {
                                    if (dtm > maxDate)
                                    {
                                        // 超出最大日期，不显示
                                        break;
                                    }
                                }
                                //循环遍历生成规则
                                string text = "";
                                int tempday = line.InRuntimeStartDate.Count;
                                //倒叙排列
                                List<DateTime> tempInRuntimeStartDate = line.InRuntimeStartDate;
                                for (int i = 0; i < tempInRuntimeStartDate.Count - 1; i++)
                                {
                                    for (int j = 0; j < tempInRuntimeStartDate.Count - i - 1; j++)
                                    {
                                        if (tempInRuntimeStartDate[j] < tempInRuntimeStartDate[j + 1])
                                        {
                                            DateTime temp = new DateTime();
                                            temp = tempInRuntimeStartDate[j + 1];
                                            tempInRuntimeStartDate[j + 1] = tempInRuntimeStartDate[j];
                                            tempInRuntimeStartDate[j] = temp;
                                        }
                                    }
                                }
                                foreach (DateTime InRuntimeStartDates in tempInRuntimeStartDate)
                                {
                                    // 获得时间差
                                    TimeSpan span = Convert.ToDateTime(dtm.ToString("yyyy-MM-dd 00:00:00")) - InRuntimeStartDates;
                                    if (span.Days == 0)
                                    {
                                        if (line.ValueType == TitleLineValueType.ChildBirthDay)
                                        {
                                            text += "分娩" + options.InShowType;
                                        }
                                        else if (line.ValueType == TitleLineValueType.DayIndex && 
                                                 !line.Text.Contains("出生"))
                                        {
                                            text += "手术(" + tempday + ")" + options.InShowType;
                                        }
                                    }
                                    else if (span.Days > 0 && (span.Days + options.DateBeginDay) <= options.DateOverDay)//超出多少天不显示
                                    {
                                        if (existData[dayIndex] || WhetherAllFalse(existData, dtm))
                                        {
                                            text += (span.Days + options.DateBeginDay).ToString() + options.InShowType;//options.InShowType-"/"
                                        }
                                    }
                                    tempday--;

                                }
                                if (text.Length > 0 && !string.IsNullOrEmpty(text.Substring(0, text.Length - 1)))
                                {
                                    g.DrawString(
        text.Substring(0, text.Length - 1),
        labelFont,
        Brushes.Red,
        new RectangleF(
            dataGridBounds.Left + dayStep * dayIndex,
            line.Top,
            dayStep,
            titleLineHeight),
        centerFormat);
                                }

                            }//for
                        }//if
                    }
                    tempIndex++;
                }
            }//for
            float sumheight = 0f;
            if (options.FooterLines.Count > 0)
            {
                // 绘制页脚内容
                float topCount = dataGridBounds.Bottom;
                float heights = titleLineHeight;
                string LastMergeName = options.FooterLines[0].MergeName;
                int MergeCount = 0;
                float MergeTop = 0f;
              
                foreach (TitleLineInfo info in options.FooterLines)
                {
                    #region 针对页脚内容的ShowType做Check处理
                    bool showflag = false;
                    XmlNodeList FooterMeasuresNodeList = document.Options.configXml.SelectNodes("TemperatureDocument/FooterMeasures/FooterMeasure");
                    foreach (XmlNode FooterMeasuresNode in FooterMeasuresNodeList)
                    {
                        showflag = false;
                        string ShowType = FooterMeasuresNode.Attributes["ShowType"] == null ? "" : FooterMeasuresNode.Attributes["ShowType"].Value;
                        if (ShowType == "") showflag = true;
                        else{
                            if (FooterMeasuresNode.Attributes["Id"].Value == ((TitleLineValueType)info.ValueType).ToString() &&
                             ShowType.Contains(document.ShowType))
                            {
                                 showflag = true;
                                 break;
                            }
                        }
                    }
                    if (showflag != true) continue;
                    #endregion

                    //if (info.Text.Contains("体重/身高"))
                    //{
                    //    info.Text = "体重(Kg)/身高(cm)";
                    //}
                    if (info.Text.Contains("呼吸"))//当底部为呼吸时 高度特殊处理
                    {
                        heights = titleLineHeight * 2f;
                    }
                    else
                    {
                        heights = titleLineHeight;
                    }
                    info.Top = topCount;

                    if (info.MergeName != "")
                    {
                        if (LastMergeName == "") { LastMergeName = info.MergeName; MergeTop = info.Top; }
                        if (LastMergeName != info.MergeName)
                        {
                            char[] Merge = LastMergeName.ToCharArray();
                            float Mergeheight = heights * MergeCount / Merge.Length;
                            // 绘制标题1--- 竖线部分
                            for (int i = 0; i < Merge.Length; i++)
                            {
                                RectangleF titleBounds1 = new RectangleF(
                                    options.Left,
                                    MergeTop + i * Mergeheight,
                                    totalYAxisWidth * 1/ 3,
                                    Mergeheight);
                                string textBlank1 = Merge[i].ToString();
                                g.DrawString(
                                textBlank1,
                                labelFont,
                                Brushes.Black,
                                titleBounds1,
                                centerFormat);

                            }
                            //画竖线
                            g.DrawLine(
                                Pens.Black,
                                options.Left + totalYAxisWidth / 3,
                                MergeTop,
                                options.Left + totalYAxisWidth / 3,
                                MergeTop + heights * MergeCount);
                            //画横线
                            g.DrawLine(
                            Pens.Black,
                            options.Left,
                            MergeTop + heights * MergeCount,
                            options.Left + totalYAxisWidth / 3,
                            MergeTop + heights * MergeCount);

                            MergeCount = 1; 
                            LastMergeName = info.MergeName; 
                            MergeTop = info.Top;

                        }
                        else {
                            MergeCount++;
                            if (MergeTop == 0f) MergeTop = info.Top;
                        }

                        // 绘制标题2 --- 横线部分
                        RectangleF titleBounds2 = new RectangleF(
                            options.Left + totalYAxisWidth / 3,
                            info.Top,
                            totalYAxisWidth * 2 / 3,
                            heights);
                        string textBlank2 = info.Text;

                        if (string.IsNullOrEmpty(textBlank2) == false)
                        {
                            g.DrawString(
                                textBlank2,
                                labelFont,
                                Brushes.Black,
                                titleBounds2,
                                centerFormat);
                        }
                        
                    }
                    else if (info.MergeName == "" && LastMergeName != "")
                    {
                        char[] Merge = LastMergeName.ToCharArray();
                        float Mergeheight = heights * MergeCount / Merge.Length;
                        // 绘制标题1
                        for (int i = 0; i < Merge.Length; i++)
                        {
                            RectangleF titleBounds1 = new RectangleF(
                                options.Left,
                                MergeTop + i * Mergeheight,
                                totalYAxisWidth / 3,
                                Mergeheight);
                            string textBlank1 = Merge[i].ToString();
                            g.DrawString(
                            textBlank1,
                            labelFont,
                            Brushes.Black,
                            titleBounds1,
                            centerFormat);

                        }
                        //画竖线
                        g.DrawLine(
                            Pens.Black,
                            options.Left + totalYAxisWidth / 3,
                            MergeTop,
                            options.Left + totalYAxisWidth / 3,
                            MergeTop + heights * MergeCount);
                        //画横线-----合并部分（下）
                        g.DrawLine(
                            Pens.Black,
                            options.Left,
                            MergeTop + heights * MergeCount,
                            options.Left + totalYAxisWidth / 3,
                            MergeTop + heights * MergeCount);
                        //画横线-----合并部分（上）
                        g.DrawLine(
                            Pens.Black,
                            options.Left,
                            info.Top + heights,
                            options.Left + totalYAxisWidth / 3,
                            info.Top + heights);

                        MergeCount = 0;
                        LastMergeName = info.MergeName;
                        MergeTop = 0f;

                        // 绘制标题
                        RectangleF titleBounds2 = new RectangleF(
                            options.Left,
                            info.Top,
                            totalYAxisWidth,
                            heights);
                        string textBlank2 = info.Text;

                        if (string.IsNullOrEmpty(textBlank2) == false)
                        {
                            g.DrawString(
                                textBlank2,
                                labelFont,
                                Brushes.Black,
                                titleBounds2,
                                centerFormat);
                        }
                    }
                    else
                    {
                        // 绘制标题
                        RectangleF titleBounds = new RectangleF(
                            options.Left,
                            info.Top,
                            totalYAxisWidth,
                            heights);
                        string textBlank = info.Text;
                        string BlankLineText="";

                        //针对空行特殊处理
                        if (info.ValueType.ToString().Contains("Blank_Line"))
                        {
                            if (document.Blank_Lines != null)
                            {
                                string[] str = document.Blank_Lines.TrimEnd(';').Split(';');
                                foreach (string item in str)
                                {
                                    if (item.Split(',').Length == 3)
                                    {
                                        if (item.Split(',')[0] == (document.PageIndex + 1).ToString() && item.Split(',')[1] == info.ValueType.ToString())
                                        {
                                            textBlank = item.Split(',')[2];
                                            BlankLineText+=textBlank+";";
                                        }
                                    }

                                }
                            }
                        }
                        //string[] blank = document.Blank_Lines.Split(';');

                        if (string.IsNullOrEmpty(textBlank) == false)
                        {
                            //处理自定项目分行显示
                            if (BlankLineText.Contains(textBlank))
                            {
                                Font font = new Font(options.FontName,7.5f);
                                Brush fontBrush = SystemBrushes.ControlText;
                                StringFormat sf = new StringFormat();
                                sf.Alignment = StringAlignment.Center;
                                sf.LineAlignment = StringAlignment.Center;
                                g.DrawString(textBlank, font, fontBrush, titleBounds, sf);
                            }
                            else
                            {
                            g.DrawString(
                                textBlank,
                                labelFont,
                                Brushes.Black,
                                titleBounds,
                                centerFormat);
                            }

                        }                   
                        g.DrawLine(
                            Pens.Black,
                            options.Left ,
                            info.Top + heights,
                            options.Left + totalYAxisWidth / 3,
                            info.Top + heights);
                    }
                    // 绘制内容
                    for (int dayIndex = 0; dayIndex < options.NumOfDaysInOnePage; dayIndex++)
                    {
                        #region 绘制内容
                        DateTime dtm = startDate.AddDays(dayIndex);
                        dtm = dtm.Date;

                        int split = info.Splits;
                        //绘制底部小边框
                        for (int j = 0; j < split; j++)
                        {
                            g.DrawRectangle(
                                Pens.Black,
                                dataGridBounds.Left + dayIndex * dataGridBounds.Width / document.Options.NumOfDaysInOnePage + j * dataGridBounds.Width / (options.NumOfDaysInOnePage * split),
                                info.Top,
                                dataGridBounds.Width / (options.NumOfDaysInOnePage * split),
                                heights);
                        }

                        foreach (FooterMeasure cm in document.FooterMeasures)
                        {
                            if (cm.ValueDate.Date == dtm)
                            {
                                string text = info.GetText(cm);
                                if (string.IsNullOrEmpty(text) == false)
                                {
                                    text = text.Replace("々", "");
                                    string[] texts = text.Split('¤');
                                    string[] CustomBreaths = null;
                                    if (options.CustomBreath == "1")
                                    {
                                        CustomBreaths = !string.IsNullOrEmpty(cm.CustomBreath) ? cm.CustomBreath.Split('¤') : null;
                                    }
                                    for (int i = 0; i < texts.Length; i++)
                                    {                                   
                                        if (info.Text.Contains("呼吸"))//当底部为呼吸时 高度特殊处理
                                        {
                                            #region 呼吸位置特殊处理
                                            Font labelFontR = null;
                                            Brush brushR = null;
                                            if (texts[i].ToString().Contains("R") || texts[i].ToString().Contains("r") || texts[i].ToString().Contains("®"))
                                            {
                                                texts[i] = "®";
                                                if (string.IsNullOrEmpty(options.FontName))
                                                {
                                                    labelFontR = new Font(
                                                        System.Windows.Forms.Control.DefaultFont.Name,
                                                        options.FontSize * 2);
                                                }
                                                else
                                                {
                                                    labelFontR = new Font(
                                                        options.FontName,
                                                        options.FontSize * 2);
                                                }
                                                brushR = Brushes.Red;
                                            }
                                            else
                                            {
                                                labelFontR = labelFont;
                                                brushR = Brushes.Black;
                                            }
                                           
                                            //呼吸位置特殊处理
                                            if (options.CustomBreath == "1" && CustomBreaths.Length == texts.Length)
                                            {
                                                if (printType == 1)
                                                {
                                                    if (CustomBreaths[i] == "1")
                                                    {
                                                        // 计算文本内容位置
                                                        RectangleF textBounds = new RectangleF(
                                                            (dataGridBounds.Left + dayIndex * dataGridBounds.Width / document.Options.NumOfDaysInOnePage + i * dataGridBounds.Width / (options.NumOfDaysInOnePage * split)) - 3,
                                                            info.Top - 25,
                                                            dataGridBounds.Width / (options.NumOfDaysInOnePage * split) + 13,
                                                            heights);
                                                        // 绘制文本内容
                                                        g.DrawString(
                                                            texts[i],
                                                            labelFontR,
                                                            brushR,
                                                            textBounds,
                                                            centerFormat);
                                                    }
                                                    else
                                                    {
                                                        // 计算文本内容位置
                                                        RectangleF textBounds = new RectangleF(
                                                            (dataGridBounds.Left + dayIndex * dataGridBounds.Width / document.Options.NumOfDaysInOnePage + i * dataGridBounds.Width / (options.NumOfDaysInOnePage * split)) - 3,
                                                            info.Top + 25,
                                                            dataGridBounds.Width / (options.NumOfDaysInOnePage * split) + 13,
                                                            heights);
                                                        // 绘制文本内容
                                                        g.DrawString(
                                                            texts[i],
                                                            labelFontR,
                                                            brushR,
                                                            textBounds,
                                                            centerFormat);
                                                    }
                                                }
                                                else
                                                {
                                                    if (CustomBreaths[i] == "1")
                                                    {
                                                        // 计算文本内容位置
                                                        RectangleF textBounds = new RectangleF(
                                                            (dataGridBounds.Left + dayIndex * dataGridBounds.Width / document.Options.NumOfDaysInOnePage + i * dataGridBounds.Width / (options.NumOfDaysInOnePage * split)) - 1,
                                                            info.Top - 10,
                                                            dataGridBounds.Width / (options.NumOfDaysInOnePage * split) + 3,
                                                            heights);
                                                        // 绘制文本内容
                                                        g.DrawString(
                                                            texts[i],
                                                            labelFontR,
                                                            brushR,
                                                            textBounds,
                                                            centerFormat);
                                                    }
                                                    else
                                                    {
                                                        // 计算文本内容位置
                                                        RectangleF textBounds = new RectangleF(
                                                            (dataGridBounds.Left + dayIndex * dataGridBounds.Width / document.Options.NumOfDaysInOnePage + i * dataGridBounds.Width / (options.NumOfDaysInOnePage * split)) - 1,
                                                            info.Top + 10,
                                                            dataGridBounds.Width / (options.NumOfDaysInOnePage * split) + 3,
                                                            heights);
                                                        // 绘制文本内容
                                                        g.DrawString(
                                                            texts[i],
                                                            labelFontR,
                                                            brushR,
                                                            textBounds,
                                                            centerFormat);
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                if (printType == 1)
                                                {
                                                    if (i % 2 == 0)
                                                    {
                                                        // 计算文本内容位置
                                                        RectangleF textBounds = new RectangleF(
                                                            (dataGridBounds.Left + dayIndex * dataGridBounds.Width / document.Options.NumOfDaysInOnePage + i * dataGridBounds.Width / (options.NumOfDaysInOnePage * split)) - 3,
                                                            info.Top - 25,
                                                            dataGridBounds.Width / (options.NumOfDaysInOnePage * split) + 13,
                                                            heights);
                                                        // 绘制文本内容
                                                        g.DrawString(
                                                            texts[i],
                                                            labelFontR,
                                                            brushR,
                                                            textBounds,
                                                            centerFormat);
                                                    }
                                                    else
                                                    {
                                                        // 计算文本内容位置
                                                        RectangleF textBounds = new RectangleF(
                                                            (dataGridBounds.Left + dayIndex * dataGridBounds.Width / document.Options.NumOfDaysInOnePage + i * dataGridBounds.Width / (options.NumOfDaysInOnePage * split)) - 3,
                                                            info.Top + 25,
                                                            dataGridBounds.Width / (options.NumOfDaysInOnePage * split) + 13,
                                                            heights);
                                                        // 绘制文本内容
                                                        g.DrawString(
                                                            texts[i],
                                                            labelFontR,
                                                            brushR,
                                                            textBounds,
                                                            centerFormat);
                                                    }
                                                }
                                                else
                                                {
                                                    if (i % 2 == 0)
                                                    {
                                                        // 计算文本内容位置
                                                        RectangleF textBounds = new RectangleF(
                                                            (dataGridBounds.Left + dayIndex * dataGridBounds.Width / document.Options.NumOfDaysInOnePage + i * dataGridBounds.Width / (options.NumOfDaysInOnePage * split)) - 1,
                                                            info.Top - 10,
                                                            dataGridBounds.Width / (options.NumOfDaysInOnePage * split) + 3,
                                                            heights);
                                                        // 绘制文本内容
                                                        g.DrawString(
                                                            texts[i],
                                                            labelFontR,
                                                            brushR,
                                                            textBounds,
                                                            centerFormat);
                                                    }
                                                    else
                                                    {
                                                        // 计算文本内容位置
                                                        RectangleF textBounds = new RectangleF(
                                                            (dataGridBounds.Left + dayIndex * dataGridBounds.Width / document.Options.NumOfDaysInOnePage + i * dataGridBounds.Width / (options.NumOfDaysInOnePage * split)) - 1,
                                                            info.Top + 10,
                                                            dataGridBounds.Width / (options.NumOfDaysInOnePage * split) + 3,
                                                            heights);
                                                        // 绘制文本内容
                                                        g.DrawString(
                                                            texts[i],
                                                            labelFontR,
                                                            brushR,
                                                            textBounds,
                                                            centerFormat);
                                                    }
                                                }
                                            }
                                            #endregion
                                        }
                                        else if (info.Text.Contains("药敏试验") ||
                                                 info.Text.Contains("药物过敏"))//当底部为药敏试验时
                                        {
                                            if (printType == 1)
                                            {
                                                // 计算文本内容位置
                                                RectangleF textBounds = new RectangleF(
                                                    (dataGridBounds.Left + dayIndex * dataGridBounds.Width / document.Options.NumOfDaysInOnePage + i * dataGridBounds.Width / (options.NumOfDaysInOnePage * split)) - 1,
                                                    info.Top,
                                                    dataGridBounds.Width / (options.NumOfDaysInOnePage * split) + 3,
                                                    heights);
                                                // 绘制文本内容
                                                g.DrawString(
                                                    texts[i],
                                                    labelFont,
                                                    Brushes.Black,
                                                    textBounds,
                                                    centerFormat);
                                            }
                                            else
                                            {
                                                #region 药敏试验 特殊处理
                                                string drugTestFirst = "";
                                                string drugTestSecond = "";
                                                string drugTestLast = "";
                                                if (texts[i].ToString().Contains("阳性") && texts[i].ToString().Length>2)
                                                {
                                                    // 计算文本内容位置                                                             
                                                    RectangleF textBound1 = new RectangleF(
                                                          (dataGridBounds.Left + dayIndex * dataGridBounds.Width / document.Options.NumOfDaysInOnePage + i * dataGridBounds.Width / (options.NumOfDaysInOnePage * split)) - 18,
                                                          info.Top,
                                                          dataGridBounds.Width / (options.NumOfDaysInOnePage * split) + 3,
                                                          heights);
                                                    RectangleF textBound2 = new RectangleF(
                                                          (dataGridBounds.Left + dayIndex * dataGridBounds.Width / document.Options.NumOfDaysInOnePage + i * dataGridBounds.Width / (options.NumOfDaysInOnePage * split)) + 10,
                                                           info.Top,
                                                           dataGridBounds.Width / (options.NumOfDaysInOnePage * split) + 3,
                                                           heights);
                                                    RectangleF textBound3 = new RectangleF(
                                                         (dataGridBounds.Left + dayIndex * dataGridBounds.Width / document.Options.NumOfDaysInOnePage + i * dataGridBounds.Width / (options.NumOfDaysInOnePage * split)) + 25,
                                                          info.Top,
                                                          dataGridBounds.Width / (options.NumOfDaysInOnePage * split) + 3,
                                                           heights);
                                                    RectangleF textBound4 = new RectangleF(
                                                         (dataGridBounds.Left + dayIndex * dataGridBounds.Width / document.Options.NumOfDaysInOnePage + i * dataGridBounds.Width / (options.NumOfDaysInOnePage * split)) + 40,
                                                          info.Top,
                                                          dataGridBounds.Width / (options.NumOfDaysInOnePage * split) + 3,
                                                           heights);
                                                    string temp = texts[i].ToString();
                                                    int drugindex = temp.IndexOf("阳性");
                                                    drugTestLast = temp.Substring(drugindex + 2, temp.Length - 2 - drugindex);
                                                    drugTestSecond = temp.Substring(drugindex - 1, 1);
                                                    drugTestFirst = temp.Substring(0, drugindex - 1);
                                                    g.DrawString(
                                                            drugTestFirst,
                                                            labelFont,
                                                            Brushes.Black,
                                                            textBound1,
                                                            centerFormat);
                                                    g.DrawString(
                                                            drugTestSecond,
                                                            labelFont,
                                                            Brushes.Black,
                                                            textBound2,
                                                            centerFormat);
                                                    g.DrawString(
                                                           "阳性",
                                                           labelFont,
                                                           Brushes.Red,
                                                           textBound3,
                                                           centerFormat);
                                                    g.DrawString(
                                                           drugTestLast,
                                                           labelFont,
                                                           Brushes.Black,
                                                           textBound4,
                                                           centerFormat);
                                                }
                                                else if (texts[i].ToString().Contains("+") && texts[i].ToString().Length > 2)
                                                {
                                                    // 计算文本内容位置                                                             
                                                    RectangleF textBound1 = new RectangleF(
                                                          (dataGridBounds.Left + dayIndex * dataGridBounds.Width / document.Options.NumOfDaysInOnePage + i * dataGridBounds.Width / (options.NumOfDaysInOnePage * split)) - 15,
                                                          info.Top,
                                                          dataGridBounds.Width / (options.NumOfDaysInOnePage * split) + 3,
                                                          heights);
                                                    RectangleF textBound2 = new RectangleF(
                                                          (dataGridBounds.Left + dayIndex * dataGridBounds.Width / document.Options.NumOfDaysInOnePage + i * dataGridBounds.Width / (options.NumOfDaysInOnePage * split)) + 17,
                                                           info.Top,
                                                           dataGridBounds.Width / (options.NumOfDaysInOnePage * split) + 3,
                                                           heights);
                                                    RectangleF textBound3 = new RectangleF(
                                                          (dataGridBounds.Left + dayIndex * dataGridBounds.Width / document.Options.NumOfDaysInOnePage + i * dataGridBounds.Width / (options.NumOfDaysInOnePage * split)) + 27,
                                                           info.Top,
                                                           dataGridBounds.Width / (options.NumOfDaysInOnePage * split) + 3,
                                                           heights);
                                                    RectangleF textBound4 = new RectangleF(
                                                           (dataGridBounds.Left + dayIndex * dataGridBounds.Width / document.Options.NumOfDaysInOnePage + i * dataGridBounds.Width / (options.NumOfDaysInOnePage * split)) + 37,
                                                           info.Top,
                                                           dataGridBounds.Width / (options.NumOfDaysInOnePage * split) + 3,
                                                           heights);
                                                    string temp = texts[i].ToString();
                                                    int drugindex = temp.IndexOf("+");
                                                    drugTestLast = temp.Substring(drugindex + 1, temp.Length - 1 - drugindex);
                                                    drugTestSecond = temp.Substring(drugindex - 1, 1);
                                                    drugTestFirst = temp.Substring(0, drugindex - 1);
                                                    g.DrawString(
                                                            drugTestFirst,
                                                            labelFont,
                                                            Brushes.Black,
                                                            textBound1,
                                                            centerFormat);
                                                    g.DrawString(
                                                           drugTestSecond,
                                                           labelFont,
                                                           Brushes.Black,
                                                           textBound2,
                                                           centerFormat);
                                                    g.DrawString(
                                                           "+",
                                                           labelFont,
                                                           Brushes.Red,
                                                           textBound3,
                                                           centerFormat);
                                                    g.DrawString(
                                                           drugTestLast,
                                                           labelFont,
                                                           Brushes.Black,
                                                           textBound4,
                                                           centerFormat);
                                                }
                                                else
                                                {
                                                    // 计算文本内容位置
                                                    RectangleF textBounds = new RectangleF(
                                                        (dataGridBounds.Left + dayIndex * dataGridBounds.Width / document.Options.NumOfDaysInOnePage + i * dataGridBounds.Width / (options.NumOfDaysInOnePage * split)) - 1,
                                                        info.Top,
                                                        dataGridBounds.Width / (options.NumOfDaysInOnePage * split) + 3,
                                                        heights);
                                                    // 绘制文本内容
                                                    g.DrawString(
                                                        texts[i],
                                                        labelFont,
                                                        Brushes.Black,
                                                        textBounds,
                                                        centerFormat);
                                                }
                                                #endregion
                                            }
                                        }
                                        else
                                        {
                                            #region 其他
                                            string TestFirst = "";
                                            string TestSecond = "";
                                            string TestLast = "";
                                            if (texts[i].ToString().Contains("阳性") && texts[i].ToString().Length > 2)
                                            {
                                                // 计算文本内容位置               
                                                RectangleF textBound1 = new RectangleF(
                                                      (dataGridBounds.Left + dayIndex * dataGridBounds.Width / document.Options.NumOfDaysInOnePage + i * dataGridBounds.Width / (options.NumOfDaysInOnePage * split)) - 18,
                                                      info.Top,
                                                      dataGridBounds.Width / (options.NumOfDaysInOnePage * split) + 3,
                                                      heights);
                                                RectangleF textBound2 = new RectangleF(
                                                      (dataGridBounds.Left + dayIndex * dataGridBounds.Width / document.Options.NumOfDaysInOnePage + i * dataGridBounds.Width / (options.NumOfDaysInOnePage * split)) + 10,
                                                       info.Top,
                                                       dataGridBounds.Width / (options.NumOfDaysInOnePage * split) + 3,
                                                       heights);
                                                RectangleF textBound3 = new RectangleF(
                                                      (dataGridBounds.Left + dayIndex * dataGridBounds.Width / document.Options.NumOfDaysInOnePage + i * dataGridBounds.Width / (options.NumOfDaysInOnePage * split)) + 25,
                                                       info.Top,
                                                       dataGridBounds.Width / (options.NumOfDaysInOnePage * split) + 3,
                                                       heights);
                                                RectangleF textBound4 = new RectangleF(
                                                      (dataGridBounds.Left + dayIndex * dataGridBounds.Width / document.Options.NumOfDaysInOnePage + i * dataGridBounds.Width / (options.NumOfDaysInOnePage * split)) + 40,
                                                       info.Top,
                                                       dataGridBounds.Width / (options.NumOfDaysInOnePage * split) + 3,
                                                       heights);
                                                string temp = texts[i].ToString();
                                                int drugindex = temp.IndexOf("阳性");
                                                TestLast = temp.Substring(drugindex + 1, temp.Length - 1 - drugindex);
                                                TestSecond = temp.Substring(drugindex - 1, 1);
                                                TestFirst = temp.Substring(0, drugindex);
                                                g.DrawString(
                                                        TestFirst,
                                                        labelFont,
                                                        Brushes.Black,
                                                        textBound1,
                                                        centerFormat);
                                                g.DrawString(
                                                       TestSecond,
                                                       labelFont,
                                                       Brushes.Black,
                                                       textBound2,
                                                       centerFormat);
                                                g.DrawString(
                                                       "阳性",
                                                       labelFont,
                                                       Brushes.Red,
                                                       textBound3,
                                                       centerFormat);
                                                g.DrawString(
                                                       TestLast,
                                                       labelFont,
                                                       Brushes.Black,
                                                       textBound4,
                                                       centerFormat);
                                            }
                                            else if (texts[i].ToString().Contains("+") && texts[i].ToString().Length > 2)
                                            {
                                                // 计算文本内容位置                                                             
                                                RectangleF textBound1 = new RectangleF(
                                                      (dataGridBounds.Left + dayIndex * dataGridBounds.Width / document.Options.NumOfDaysInOnePage + i * dataGridBounds.Width / (options.NumOfDaysInOnePage * split)) - 15,
                                                      info.Top,
                                                      dataGridBounds.Width / (options.NumOfDaysInOnePage * split) + 3,
                                                      heights);
                                                RectangleF textBound2 = new RectangleF(
                                                     (dataGridBounds.Left + dayIndex * dataGridBounds.Width / document.Options.NumOfDaysInOnePage + i * dataGridBounds.Width / (options.NumOfDaysInOnePage * split)) + 17,
                                                      info.Top,
                                                      dataGridBounds.Width / (options.NumOfDaysInOnePage * split) + 3,
                                                      heights);
                                                RectangleF textBound3 = new RectangleF(
                                                     (dataGridBounds.Left + dayIndex * dataGridBounds.Width / document.Options.NumOfDaysInOnePage + i * dataGridBounds.Width / (options.NumOfDaysInOnePage * split)) + 27,
                                                      info.Top,
                                                      dataGridBounds.Width / (options.NumOfDaysInOnePage * split) + 3,
                                                      heights);
                                                RectangleF textBound4 = new RectangleF(
                                                     (dataGridBounds.Left + dayIndex * dataGridBounds.Width / document.Options.NumOfDaysInOnePage + i * dataGridBounds.Width / (options.NumOfDaysInOnePage * split)) + 37,
                                                      info.Top,
                                                      dataGridBounds.Width / (options.NumOfDaysInOnePage * split) + 3,
                                                      heights);
                                                string temp = texts[i].ToString();
                                                int drugindex = temp.IndexOf("+");
                                                TestLast = temp.Substring(drugindex + 2, temp.Length - 2 - drugindex);
                                                TestSecond = temp.Substring(drugindex - 1, 1);
                                                TestFirst = temp.Substring(0, drugindex - 1);
                                                g.DrawString(
                                                        TestFirst,
                                                        labelFont,
                                                        Brushes.Black,
                                                        textBound1,
                                                        centerFormat);
                                                g.DrawString(
                                                        TestSecond,
                                                        labelFont,
                                                        Brushes.Black,
                                                        textBound2,
                                                        centerFormat);
                                                g.DrawString(
                                                       "+",
                                                       labelFont,
                                                       Brushes.Red,
                                                       textBound3,
                                                       centerFormat);
                                                g.DrawString(
                                                       TestLast,
                                                       labelFont,
                                                       Brushes.Black,
                                                       textBound4,
                                                       centerFormat);
                                            }
                                            else
                                            {
                                                // 计算文本内容位置
                                                RectangleF textBounds = new RectangleF(
                                                    (dataGridBounds.Left + dayIndex * dataGridBounds.Width / document.Options.NumOfDaysInOnePage + i * dataGridBounds.Width / (options.NumOfDaysInOnePage * split)) - 1,
                                                    info.Top,
                                                    dataGridBounds.Width / (options.NumOfDaysInOnePage * split) + 3,
                                                    heights);
                                                if (split == 2)
                                                {
                                                    if (printType == 1)
                                                    {
                                                        Font labelFont2 = new Font(options.FontName,7.5f);
                                                        // 绘制文本内容
                                                        g.DrawString(
                                                            texts[i],
                                                            labelFont2,
                                                            Brushes.Black,
                                                            textBounds,
                                                            centerFormat);
                                                    }
                                                    else
                                                    {
                                                        Font labelFont2 = new Font(options.FontName, 7.8f);
                                                        // 绘制文本内容
                                                        g.DrawString(
                                                            texts[i],
                                                            labelFont2,
                                                            Brushes.Black,
                                                            textBounds,
                                                            centerFormat);
                                                    }
                                                }
                                                else
                                                {
                                                    // 绘制文本内容
                                                    g.DrawString(
                                                        texts[i],
                                                        labelFont,
                                                        Brushes.Black,
                                                        textBounds,
                                                        centerFormat);
                                                }
                                            }
                                            #endregion
                                        }

                                    }
                                }//if
                                break;
                            }//if
                        }//foreach
                        #endregion
                    }//for


                    // 绘制横线
                    g.DrawLine(
                            Pens.Black,
                            options.Left + totalYAxisWidth / 3 ,
                            info.Top + heights,
                            options.Left + options.Width,
                            info.Top + heights);
                    topCount = topCount + heights;
                }
                sumheight = topCount;
            }

            if (options.FooterRemarks.Count > 0)
            {
                // 绘制页脚内容
                float topCount = dataGridBounds.Bottom;
                float heights = footRemarkHeight;
                foreach (FooterRemark info in options.FooterRemarks)
                {
                    if (info.ShowType == document.ShowType)
                    {
                        // 绘制标题
                        RectangleF titleBounds = new RectangleF(
                            options.Left,
                            sumheight,
                            options.Width,
                            heights);
                        string textBlank = info.Text;

                        g.DrawString(
                                textBlank,
                                labelFont,
                                Brushes.Black,
                                titleBounds,
                                leftFormat);
                    }
                }
            }
            //此处注释，向上移动
            //// 绘制大竖线
            //Pen p_v = new Pen(Color.Red, 2);//配置项
            //if (printType == 1)
            //{
            //    p_v = new Pen(Color.Red, 5);
            //}

            //for (int lineIndex = 0; lineIndex < options.NumOfDaysInOnePage; lineIndex++)//lineIndex <= options.NumOfDaysInOnePage; lineIndex++)
            //{
            //    if (lineIndex != 0)
            //    {
            //        g.DrawLine(
            //            p_v,
            //            //lineIndex == 0 || lineIndex == options.NumOfDaysInOnePage ? Pens.Black : Pens.Red,
            //            dataGridBounds.Left + dayStep * lineIndex,
            //            options.Top + titleHeight,
            //            dataGridBounds.Left + dayStep * lineIndex,
            //            options.Top + options.Height);
            //    }//for
            //    else
            //    {
            //        g.DrawLine(
            //            Pens.Black,
            //            dataGridBounds.Left + dayStep * lineIndex,
            //            options.Top + titleHeight,
            //            dataGridBounds.Left + dayStep * lineIndex,
            //            options.Top + options.Height);
            //    }
            //}

            // 绘制大边框
            Pen pall = new Pen(Color.Black, 2);
            if (printType == 1)
            {
                pall = new Pen(Color.Black, 5);
            }
            g.DrawRectangle(
                pall,
                options.Left,
                options.Top + titleHeight,
                options.Width,
                options.Height - titleHeight);

            //有说明字段  显示说明字段和页码
            if (!string.IsNullOrEmpty(options.Remark))
            {
                string remark = options.Remark;
                string page = "第 " + (document.PageIndex + 1) + " 页";
                using (Font pageFont = new Font(
    labelFont.Name,
    labelFont.Size,
    labelFont.Style))
                {
                    if (printType == 1)
                    {
                        RectangleF remarkTextBounds = new RectangleF(
options.Left,
options.Top + options.Height - titleHeight / 3,
options.Width,
titleHeight);
                        g.DrawString(
                           remark,
                            pageFont,
                            Brushes.Black,
                            remarkTextBounds,
                            centerFormat);
                        RectangleF pageTextBounds = new RectangleF(
        options.Left,
        options.Top + options.Height - titleHeight / 3 + titleHeight / 4,
        options.Width,
        titleHeight);
                        g.DrawString(
                           page,
                            pageFont,
                            Brushes.Black,
                            pageTextBounds,
                            centerFormat);
                    }
                    else
                    {
                        RectangleF remarkTextBounds = new RectangleF(
options.Left,
options.Top + options.Height - 32,
options.Width,
titleHeight);
                        g.DrawString(
   remark,
    pageFont,
    Brushes.Black,
    remarkTextBounds,
    centerFormat);
                        RectangleF pageTextBounds = new RectangleF(
        options.Left,
        options.Top + options.Height - 16,
        options.Width,
        titleHeight);
                        g.DrawString(
                            page,
                            pageFont,
                            Brushes.Black,
                            pageTextBounds,
                            centerFormat);
                    }

                }

            }
            //无说明字段 只显示页码
            else
            {
                string page = "第 " + (document.PageIndex + 1) + " 页";
                using (Font pageFont = new Font(
    labelFont.Name,
    labelFont.Size,
    labelFont.Style))
                {
                    if (printType == 1)
                    {
                        RectangleF pageTextBounds = new RectangleF(
        options.Left,
        options.Top + options.Height - titleHeight / 3,
        options.Width,
        titleHeight);
                        g.DrawString(
                           page,
                            pageFont,
                            Brushes.Black,
                            pageTextBounds,
                            centerFormat);
                    }
                    else
                    {
                        RectangleF pageTextBounds = new RectangleF(
        options.Left,
        options.Top + options.Height - 20,
        options.Width,
        titleHeight);
                        g.DrawString(
                           page,
                            pageFont,
                            Brushes.Black,
                            pageTextBounds,
                            centerFormat);
                    }

                }
            }

            labelFont.Dispose();
            centerFormat.Dispose();
        }

        private bool WhetherAllFalse(bool[] array, DateTime dtm)
        {
            bool result = true;
            //是否全为false，如果全为false，即当周没有出院，如果有true，即当周某一天为出院
            for (int i = 0; i < array.Length; ++i)
            {
                if (array[i])
                {
                    result = false;
                    break;
                }
            }

            //当前日期是否比系统日期小
            if (result)
            {
                if (DateTime.Compare(dtm.Date,DateTime.Now.Date)>0)
                {
                    result = false;
                }
            }
            return result;
        }

        /// <summary>
        /// 绘制网格线
        /// </summary>
        /// <param name="g"></param>
        /// <param name="rect"></param>
        /// <param name="xNum"></param>
        /// <param name="yNum"></param>
        /// <param name="p"></param>
        private void DrawGrid(Graphics g, RectangleF rect, int xNum, int yNum, Pen p, int YSplitLittleNum, int YSplitLittleNums)
        {
            Pen p_h = new Pen(Color.DarkBlue, 2);//配置项 网格大横线
            if (printType == 1)
            {
                p_h = new Pen(Color.DarkBlue, 5);
            }
            for (int x = 0; x < xNum; x++)
            {
                g.DrawLine(
                    p,
                    rect.Left + rect.Width * x / xNum,
                    rect.Top,
                    rect.Left + rect.Width * x / xNum,
                    rect.Bottom);
            }
            for (int y = 0; y < yNum; y++)//最后一行横线不绘制for (int y = 0; y <= yNum; y++)
            {
                if ((y - YSplitLittleNum) != 0 && (y - YSplitLittleNum) % 5 == 0)
                {
                    //下事件起绘位置
                    if (y == yNum - 5)//倒数第二行
                    {
                        MemoUp = rect.Top + rect.Height * y / yNum;
                    }

                    g.DrawLine(
                        p_h,
                        rect.Left,
                        rect.Top + rect.Height * y / yNum,
                        rect.Right,
                        rect.Top + rect.Height * y / yNum);


                }
                //为区分顶部是否有小格进行特殊处理
                else if ((y - YSplitLittleNum) == 0 && (y - YSplitLittleNum) % 5 == 0)
                {
                    //上事件起绘位置
                    MemoIn = rect.Top + rect.Height * y / yNum;
                    if (YSplitLittleNum != 0)
                    {
                        g.DrawLine(
                            p_h,
                            rect.Left,
                            rect.Top + rect.Height * y / yNum,
                            rect.Right,
                            rect.Top + rect.Height * y / yNum);
                    }
                }
                else
                {
                    g.DrawLine(
                        p,
                        rect.Left,
                        rect.Top + rect.Height * y / yNum,
                        rect.Right,
                        rect.Top + rect.Height * y / yNum);

                }
                //Y轴一大格分多少小
                if (YSplitLittleNums / 5 != 1)
                {
                    g.DrawLine(
p,
rect.Left,
rect.Top + rect.Height * y / yNum + rect.Height / (yNum * YSplitLittleNums / 5),
rect.Right,
rect.Top + rect.Height * y / yNum + rect.Height / (yNum * YSplitLittleNums / 5));
                }
            }
        }

        /// <summary>
        /// 绘制数据点符号
        /// </summary>
        /// <param name="g">画布对象</param>
        /// <param name="x">X坐标</param>
        /// <param name="y">Y坐标</param>
        /// <param name="info">坐标轴信息</param>
        /// <param name="coincide">重合信息</param>
        private void DrawSymbol(Graphics g, float x, float y, YAxisInfo info, TemperatureDocumentOptions opt, string Temperature,
                                TemperatureDocument document, string[] coincide, out float SymbolSize)
        {
            PointSymbolStyle pointS = new PointSymbolStyle();
            Color SymbolColor = new Color();
            pointS = info.SymbolStyle;
            StringFormat centerFormat = new StringFormat();
            centerFormat.Alignment = StringAlignment.Center;
            centerFormat.LineAlignment = StringAlignment.Center;
            centerFormat.FormatFlags = System.Drawing.StringFormatFlags.FitBlackBox
                    | System.Drawing.StringFormatFlags.MeasureTrailingSpaces
                    | StringFormatFlags.NoClip | StringFormatFlags.NoWrap;
            float ssize = opt.SymbolSize;
            if (g.PageUnit == GraphicsUnit.Document)
            {
                ssize = ssize * 300f / 96f;
            }
            RectangleF rect = new RectangleF(
                x - ssize / 2,
                y - ssize / 2,
                ssize,
                ssize);
            SymbolSize = ssize;
            //此处过滤体温不同类型和物理降温字符
            if (info.ValueMember == ValueMemberType.Body_Temperature)//体温
            {
                XmlNodeList TemperatureNodeList = document.Options.configXml.SelectNodes("TemperatureDocument/TemperatureConfigs/TemperatureConfig");

                foreach (XmlNode TemperatureNode in TemperatureNodeList)
                {
                    if (TemperatureNode.Attributes["Id"].Value == Temperature)
                    {
                        pointS = (PointSymbolStyle)Enum.Parse(typeof(PointSymbolStyle), TemperatureNode.Attributes["PointSymbolStyle"].Value, true);
                        SymbolColor = ColorTranslator.FromHtml(TemperatureNode.Attributes["Color"].Value);
                    }
                    //else
                    //{
                    //    pointS = info.SymbolStyle;
                    //    SymbolColor = info.SymbolColor;
                    //}
                }
            }
            else if (info.ValueMember == ValueMemberType.Pluse)
            {
                pointS = (Temperature == "起搏器") ? PointSymbolStyle.PluseShow : info.SymbolStyle;
                SymbolColor = info.SymbolColor;
            }
            else if (info.ValueMember == ValueMemberType.Breath)
            {
                pointS = (Temperature == "呼吸机") ? PointSymbolStyle.BreathShow : info.SymbolStyle;
                SymbolColor = info.SymbolColor;
            }
            else
            {
                pointS = info.SymbolStyle;
                SymbolColor = info.SymbolColor;
            }

            float width = 2f;
            if (printType == 1)
            {
                width = 5f;
            }

            //根据是否重合信息重新check图形
            if (!string.IsNullOrEmpty(coincide[0])) //体温和脉搏重合
            {
                if (info.ValueMember == ValueMemberType.Pluse)
                {
                    pointS = PointSymbolStyle.HollowCicle;
                    SymbolColor = info.SymbolColor;
                }
            }
            else if (!string.IsNullOrEmpty(coincide[1]))  //心率脉搏重合
            {
                if (info.ValueMember == ValueMemberType.Pluse)
                {
                    float tsize = opt.SymbolSize - 4;
                    if (g.PageUnit == GraphicsUnit.Document)
                    {
                        tsize = tsize * 300f / 96f;
                    }
                    rect = new RectangleF(
                        x - tsize / 2,
                        y - tsize / 2,
                        tsize,
                        tsize);
                }
            }

            switch (pointS)
            {
                case PointSymbolStyle.SolidCicle:
                    using (SolidBrush b = new SolidBrush(SymbolColor))
                    {
                        g.FillEllipse(
                            b,
                            rect);
                    }
                    if (!string.IsNullOrEmpty(coincide[1]))
                    {  //心率脉搏重合时，脉搏的预留半径和心率一致
                        SymbolSize -= (width + 2f);
                        if (printType == 1) SymbolSize -= (5f + 2f); //打印时特殊设置
                    }else
                        SymbolSize = 0f;
                    break;
                case PointSymbolStyle.HollowCicle:
                    using (Pen p = new Pen(SymbolColor, width))
                    {
                        RectangleF rect1 = new RectangleF(x - ssize / 2,y - ssize / 2,ssize,ssize);
                        g.DrawEllipse(
                             p,
                              rect1);
                    }
                    SymbolSize -= (width + 2f) ;
                    if (printType == 1) SymbolSize -= (5f + 2f) ; //打印时特殊设置
                    break;
                case PointSymbolStyle.Cross:
                    using (Pen p = new Pen(SymbolColor, width))
                    {
                        if (printType == 1)
                        {
                            g.DrawLine(p, rect.Left + 5, rect.Top + 5, rect.Right - 5, rect.Bottom - 5);
                            g.DrawLine(p, rect.Left + 5, rect.Bottom - 5, rect.Right - 5, rect.Top + 5);
                        }else{
                            g.DrawLine(p, rect.Left + 2, rect.Top + 2, rect.Right - 2, rect.Bottom - 2);
                            g.DrawLine(p, rect.Left + 2, rect.Bottom - 2, rect.Right - 2, rect.Top + 2);
                        }
                    }
                    SymbolSize = 0f;
                    break;
                case PointSymbolStyle.CrossCicle:
                    using (Pen p = new Pen(SymbolColor, width))
                    {
                        g.DrawLine(p, rect.Left, rect.Top, rect.Right, rect.Bottom);
                        g.DrawLine(p, rect.Left, rect.Bottom, rect.Right, rect.Top);
                        g.DrawEllipse(
                        p,
                        rect);
                    }
                    SymbolSize -= (width + 2f);
                    if (printType == 1) SymbolSize -= 7f; //打印时特殊设置
                    break;
                case PointSymbolStyle.PluseShow:
                    using (Brush b = new SolidBrush(SymbolColor))
                    {
                        Font labelFontR = new Font(
            System.Windows.Forms.Control.DefaultFont.Name,
            10);
                        g.DrawString(
                                                    "Ⓗ",
                                                    labelFontR,
                                                    b,
                                                    rect,
                                                    centerFormat);
                    }
                    break;
                case PointSymbolStyle.BreathShow:
                    using (Pen p = new Pen(SymbolColor, width))
                    {
                        RectangleF rect1 = new RectangleF(x - ssize / 2, y - ssize / 2, ssize, ssize);
                        g.DrawEllipse(
                             p,
                              rect1);
                    };

                    rect = new RectangleF(
                        rect.X,
                        rect.Y + 3,
                        rect.Width,
                        rect.Height);

                    using (Brush b = new SolidBrush(SymbolColor))
                    {
                        Font labelFontR = new Font(
            System.Windows.Forms.Control.DefaultFont.Name,
            9);
                        g.DrawString(
                                                    "R",
                                                    labelFontR,
                                                    b,
                                                    rect,
                                                    centerFormat);
                    }

                    SymbolSize -= (width + 2f) ;
                    if (printType == 1) SymbolSize -= (5f + 2f) ; //打印时特殊设置
                    break;
            }
        }
        /// <summary>
        /// 绘制多边形并填充斜线阴影
        /// </summary>
        /// <param name="g">画布对象</param>
        /// <param name="curvePoints">多边形点</param>
        private void DrawPolygon(Graphics g, PointF[] curvePoints) 
        {
            Pen blackPen = new Pen(Color.Transparent, 2);
            // 绘制多边形.
            g.DrawPolygon(blackPen, curvePoints);
            //阴影画刷填充图形使用前景色、背景色和阴影样式(斜线)
            HatchBrush myHatchBrush = new HatchBrush(HatchStyle.BackwardDiagonal, Color.Red, Color.Transparent);
            g.FillPolygon(myHatchBrush, curvePoints);
        }
        /// <summary>
        /// 查询point是否在List集合中存在
        /// </summary>
        /// <param name="pointFList"></param>
        /// <param name="point"></param>
        /// <returns></returns>
        private bool DistinctPoint(List<PointF> pointFList, PointF point)
        {
            bool result = true;
             foreach (PointF item in pointFList)
                {
                    if (item.X == point.X&&item.Y==point.Y)
                    {
                        result = false;
                    }                 
            }
             return result;
        }

        private string[] UpdateTransferBedOrDept(TemperatureDocument document)
        {
            TemperatureDocumentOptions options = document.Options;
            string[] result = new string[2]; // result[0]存放转床;result[1]存放转科
            // 有数据的时间区间的最大值
            DateTime maxDate = TemperatureDocument.NullDate;
            // 有数据的时间区间的最小值
            DateTime minDate = TemperatureDocument.NullDate;
            document.UpdateNumOfPage(out maxDate, out minDate);
            // 当前区域的开始时间
            DateTime startDate = minDate.AddDays(
                document.PageIndex * options.NumOfDaysInOnePage);
            // 当前区域的截至时间
            DateTime endDate = startDate.AddDays(options.NumOfDaysInOnePage);
            string resultList = "";
            #region 转科
            if (string.IsNullOrEmpty(document.TransferSection)) { result[1] = ""; }
            else
            {
                string[] DeptList = document.TransferSection.Split(';');
                string[] DeptTimeList = document.TransferSectionTime.Split(';');
                for (int i = 0; i < DeptList.Length; i++)
                {
                    DateTime time = Convert.ToDateTime(DeptTimeList[i]);
                    if (time.Date >= startDate.Date && time.Date <= endDate.Date)
                    {
                        if (resultList == "") resultList = DeptList[i].ToString().Split(',')[0] + "->" +
                                                           DeptList[i].ToString().Split(',')[1];
                        else resultList += "->" + DeptList[i].ToString().Split(',')[1];

                    }
                }
                if (resultList == "")
                {
                    int minTransfer = -1;
                    for (int i = 0; i < DeptList.Length; i++)
                    {
                        DateTime time = Convert.ToDateTime(DeptTimeList[i]);

                        if (time.Date > startDate.Date)
                        {
                            if (i == 0) { resultList = DeptList[0].Split(',')[0]; break; } //转床都在最右侧
                            minTransfer = i - 1;
                            break;
                        }
                    }
                    if (minTransfer == -1 && resultList == "") resultList = DeptList[DeptList.Length - 1].Split(',')[1];
                    else if (resultList == "") resultList = DeptList[minTransfer].Split(',')[1];

                }
                result[1] = resultList;
            }
            #endregion

            #region 转床
            if (string.IsNullOrEmpty(document.TransferBedNo)) { result[0] = ""; }
            else
            {
                string[] BedNoList = document.TransferBedNo.Split(';');
                string[] BedNoTimeList = document.TransferBedNoTime.Split(';');
                resultList = "";
                for (int i = 0; i < BedNoList.Length; i++)
                {
                    DateTime time = Convert.ToDateTime(BedNoTimeList[i]);
                    if (time.Date >= startDate.Date && time.Date <= endDate.Date)
                    {
                        if (resultList == "") resultList = BedNoList[i].ToString().Split(',')[0] + "->" +
                                                           BedNoList[i].ToString().Split(',')[1];
                        else resultList += "->" + BedNoList[i].ToString().Split(',')[1];
                    }
                }
                if (resultList == "")
                {
                    int minTransfer = -1;
                    for (int i = 0; i < BedNoList.Length; i++)
                    {
                        DateTime time = Convert.ToDateTime(BedNoTimeList[i]);

                        if (time.Date > startDate.Date)
                        {
                            if (i == 0) { resultList = BedNoList[0].Split(',')[0]; break; } //转床都在最右侧
                            minTransfer = i - 1;
                            break;
                        }
                    }
                    if (minTransfer == -1 && resultList == "") resultList = BedNoList[BedNoList.Length - 1].Split(',')[1];
                    else if (resultList == "") resultList = BedNoList[minTransfer].Split(',')[1];
                    
                }
                result[0] = resultList;
            }
            #endregion

            return result;
        }

        #region 计算直线与圆圈交点
        private PointF getPoint(float cx, float cy, float r, float stx, float sty, float edx, float edy,int flag)
        {
           // 求直线
            float k = (edy - sty) / (edx - stx);
            float b = edy - k * edx;
            //列方程
            double x1,y1,x2,y2;
            float c = cx * cx + (b - cy) * (b - cy) - r * r;
            float a = (1 + k * k);
            float b1 = (2 * cx - 2 * k * (b - cy));

            double tmp = Math.Sqrt(b1 * b1 - 4 * a * c);
            x1 = ( b1 + tmp )/(2*a);
            y1 = k*x1 + b;
            x2 = ( b1 - tmp)/(2*a);
            y2 = k*x2 + b;
        //判断求出的点是否在圆上
            int res = (int)Math.Round((x1 - cx) * (x1 - cx) + (y1 - cy) * (y1 - cy));
            PointF p = new Point();
            if (flag == 1)  //获取X大值
            {
                if (x1 > x2) {
                    p.X = (float)x1;
                    p.Y = (float)y1;
                }
                else
                {
                    p.X = (float)x2;
                    p.Y = (float)y2;
                }
            }    
            else
            {
                if (x1 > x2)
                {
                    p.X = (float)x2;
                    p.Y = (float)y2;
                }
                else
                {
                    p.X = (float)x1;
                    p.Y = (float)y1;
                }
            }
            return p;
        }
        #endregion
    }
}
